Skip to content

Commit 44256bb

Browse files
committed
path: fix incorrect use of ERR_INVALID_ARG_TYPE
PR-URL: #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>
1 parent 1d74143 commit 44256bb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/path.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ const win32 = {
960960
format: function format(pathObject) {
961961
if (pathObject === null || typeof pathObject !== 'object') {
962962
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object',
963-
typeof pathObject);
963+
pathObject);
964964
}
965965
return _format('\\', pathObject);
966966
},
@@ -1503,7 +1503,7 @@ const posix = {
15031503
format: function format(pathObject) {
15041504
if (pathObject === null || typeof pathObject !== 'object') {
15051505
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object',
1506-
typeof pathObject);
1506+
pathObject);
15071507
}
15081508
return _format('/', pathObject);
15091509
},

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

+15
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,19 @@ function checkFormat(path, testCases) {
207207
testCases.forEach(function(testCase) {
208208
assert.strictEqual(path.format(testCase[0]), testCase[1]);
209209
});
210+
211+
function typeName(value) {
212+
return value === null ? 'null' : typeof value;
213+
}
214+
215+
[null, undefined, 1, true, false, 'string'].forEach((pathObject) => {
216+
assert.throws(() => {
217+
path.format(pathObject);
218+
}, common.expectsError({
219+
code: 'ERR_INVALID_ARG_TYPE',
220+
type: TypeError,
221+
message: 'The "pathObject" argument must be of type Object. Received ' +
222+
'type ' + typeName(pathObject)
223+
}));
224+
});
210225
}

0 commit comments

Comments
 (0)