Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 834b239

Browse files
committed
meta: merge node/master into node-chakracore/master
Merge 71396a2 as of 2017-12-27 This commit was automatically generated. For any problems, please contact jackhorton Reviewed-By: Taylor Woll <tawoll@ntdev.microsoft.com>
2 parents 3275414 + 71396a2 commit 834b239

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/fs.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ fs.accessSync = function(path, mode) {
340340
fs.exists = function(path, callback) {
341341
if (handleError((path = getPathFromURL(path)), cb))
342342
return;
343+
if (typeof path !== 'string' && !(path instanceof Buffer)) {
344+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path',
345+
['string', 'Buffer', 'URL']);
346+
}
343347
if (!nullCheck(path, cb)) return;
344348
var req = new FSReqWrap();
345349
req.oncomplete = cb;
@@ -361,6 +365,9 @@ Object.defineProperty(fs.exists, internalUtil.promisify.custom, {
361365
fs.existsSync = function(path) {
362366
try {
363367
handleError((path = getPathFromURL(path)));
368+
if (typeof path !== 'string' && !(path instanceof Buffer)) {
369+
return false;
370+
}
364371
nullCheck(path);
365372
binding.stat(pathModule.toNamespacedPath(path));
366373
return true;
@@ -389,6 +396,9 @@ fs.readFile = function(path, options, callback) {
389396
req.oncomplete(null, path);
390397
});
391398
return;
399+
} else if (typeof path !== 'string' && !(path instanceof Buffer)) {
400+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path',
401+
['string', 'Buffer', 'URL']);
392402
}
393403

394404
binding.open(pathModule.toNamespacedPath(path),

test/parallel/test-fs-exists.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,14 @@ fs.exists(new URL('https://foo'), common.mustCall(function(y) {
4242

4343
assert(fs.existsSync(f));
4444
assert(!fs.existsSync(`${f}-NO`));
45+
46+
common.expectsError(
47+
() => { fs.exists(() => {}); },
48+
{
49+
code: 'ERR_INVALID_ARG_TYPE',
50+
message: 'The "path" argument must be one of type string, Buffer, or URL',
51+
type: TypeError
52+
}
53+
);
54+
55+
assert(!fs.existsSync());

test/parallel/test-fs-readfile-error.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
'use strict';
2323
const common = require('../common');
24+
const fs = require('fs');
2425

2526
// Test that fs.readFile fails correctly on a non-existent file.
2627

@@ -54,3 +55,12 @@ test({ NODE_DEBUG: 'fs' }, common.mustCall((data) => {
5455
assert(/EISDIR/.test(data));
5556
assert(/test-fs-readfile-error/.test(data));
5657
}));
58+
59+
common.expectsError(
60+
() => { fs.readFile(() => {}); },
61+
{
62+
code: 'ERR_INVALID_ARG_TYPE',
63+
message: 'The "path" argument must be one of type string, Buffer, or URL',
64+
type: TypeError
65+
}
66+
);

0 commit comments

Comments
 (0)