From 03ee4d854744e83f99bc5857b98f75139c448564 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 19 Jan 2015 16:50:43 -0500 Subject: [PATCH] fs: add error code on null byte paths This commit adds a code field to the error returned by nullCheck(). Fixes: https://github.com/iojs/io.js/issues/517 PR-URL: https://github.com/iojs/io.js/pull/519 Reviewed-By: Ben Noordhuis --- lib/fs.js | 1 + test/parallel/test-fs-null-bytes.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/fs.js b/lib/fs.js index 2d7a038e156a66..3c0c9a95676e42 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -86,6 +86,7 @@ function assertEncoding(encoding) { function nullCheck(path, callback) { if (('' + path).indexOf('\u0000') !== -1) { var er = new Error('Path must be a string without null bytes.'); + er.code = 'ENOENT'; if (!callback) throw er; process.nextTick(function() { diff --git a/test/parallel/test-fs-null-bytes.js b/test/parallel/test-fs-null-bytes.js index f9fec809cbf864..8499c03cfe8977 100644 --- a/test/parallel/test-fs-null-bytes.js +++ b/test/parallel/test-fs-null-bytes.js @@ -7,6 +7,7 @@ function check(async, sync) { var argsSync = Array.prototype.slice.call(arguments, 2); var argsAsync = argsSync.concat(function(er) { assert(er && er.message.match(expected)); + assert.equal(er.code, 'ENOENT'); }); if (sync)