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 <info@bnoordhuis.nl>
This commit is contained in:
cjihrig 2015-01-19 16:50:43 -05:00
parent e2558f02df
commit 03ee4d8547
2 changed files with 2 additions and 0 deletions

View File

@ -86,6 +86,7 @@ function assertEncoding(encoding) {
function nullCheck(path, callback) { function nullCheck(path, callback) {
if (('' + path).indexOf('\u0000') !== -1) { if (('' + path).indexOf('\u0000') !== -1) {
var er = new Error('Path must be a string without null bytes.'); var er = new Error('Path must be a string without null bytes.');
er.code = 'ENOENT';
if (!callback) if (!callback)
throw er; throw er;
process.nextTick(function() { process.nextTick(function() {

View File

@ -7,6 +7,7 @@ function check(async, sync) {
var argsSync = Array.prototype.slice.call(arguments, 2); var argsSync = Array.prototype.slice.call(arguments, 2);
var argsAsync = argsSync.concat(function(er) { var argsAsync = argsSync.concat(function(er) {
assert(er && er.message.match(expected)); assert(er && er.message.match(expected));
assert.equal(er.code, 'ENOENT');
}); });
if (sync) if (sync)