fs: add error code on null byte paths
authorcjihrig <cjihrig@gmail.com>
Mon, 19 Jan 2015 21:50:43 +0000 (16:50 -0500)
committercjihrig <cjihrig@gmail.com>
Mon, 19 Jan 2015 23:07:46 +0000 (18:07 -0500)
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 <info@bnoordhuis.nl>
lib/fs.js
test/parallel/test-fs-null-bytes.js

index 2d7a038..3c0c9a9 100644 (file)
--- 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() {
index f9fec80..8499c03 100644 (file)
@@ -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)