From 44256bb0aaa54df60ec3d2c53bcfe7004fb61427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 30 Jun 2017 21:31:21 +0200 Subject: [PATCH] path: fix incorrect use of ERR_INVALID_ARG_TYPE PR-URL: https://github.com/nodejs/node/pull/14011 Reviewed-By: Refael Ackermann Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- lib/path.js | 4 ++-- test/parallel/test-path-parse-format.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/path.js b/lib/path.js index f8d0e822bf1d9b..001152866ffc35 100644 --- a/lib/path.js +++ b/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); }, diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index 24e49f3ffc99ea..1c3bdff130f55d 100644 --- a/test/parallel/test-path-parse-format.js +++ b/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) + })); + }); }