Skip to content

Commit 03ee4d8

Browse files
committed
fs: add error code on null byte paths
This commit adds a code field to the error returned by nullCheck(). Fixes: #517 PR-URL: #519 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent e2558f0 commit 03ee4d8

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

lib/fs.js

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function assertEncoding(encoding) {
8686
function nullCheck(path, callback) {
8787
if (('' + path).indexOf('\u0000') !== -1) {
8888
var er = new Error('Path must be a string without null bytes.');
89+
er.code = 'ENOENT';
8990
if (!callback)
9091
throw er;
9192
process.nextTick(function() {

test/parallel/test-fs-null-bytes.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function check(async, sync) {
77
var argsSync = Array.prototype.slice.call(arguments, 2);
88
var argsAsync = argsSync.concat(function(er) {
99
assert(er && er.message.match(expected));
10+
assert.equal(er.code, 'ENOENT');
1011
});
1112

1213
if (sync)

0 commit comments

Comments
 (0)