Browse Source

path: fix incorrect use of ERR_INVALID_ARG_TYPE

PR-URL: https://github.com/nodejs/node/pull/14011
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v6
Tobias Nießen 8 years ago
parent
commit
44256bb0aa
  1. 4
      lib/path.js
  2. 15
      test/parallel/test-path-parse-format.js

4
lib/path.js

@ -960,7 +960,7 @@ const win32 = {
format: function format(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object',
typeof pathObject);
pathObject);
}
return _format('\\', pathObject);
},
@ -1503,7 +1503,7 @@ const posix = {
format: function format(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object',
typeof pathObject);
pathObject);
}
return _format('/', pathObject);
},

15
test/parallel/test-path-parse-format.js

@ -207,4 +207,19 @@ function checkFormat(path, testCases) {
testCases.forEach(function(testCase) {
assert.strictEqual(path.format(testCase[0]), testCase[1]);
});
function typeName(value) {
return value === null ? 'null' : typeof value;
}
[null, undefined, 1, true, false, 'string'].forEach((pathObject) => {
assert.throws(() => {
path.format(pathObject);
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "pathObject" argument must be of type Object. Received ' +
'type ' + typeName(pathObject)
}));
});
}

Loading…
Cancel
Save