Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const {
CHAR_COLON,
CHAR_QUESTION_MARK,
} = require('internal/constants');
const {
codes: {
ERR_INVALID_ARG_TYPE,
},
} = require('internal/errors');
const {
validateObject,
validateString,
Expand Down Expand Up @@ -196,7 +201,9 @@ const win32 = {
let path;
if (i >= 0) {
path = args[i];
validateString(path, `paths[${i}]`);
if (typeof path !== 'string') {
throw new ERR_INVALID_ARG_TYPE(`paths[${i}]`, 'string', path);
}

@jasnell jasnell Nov 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: longer term, I wonder if it would be better to have a variation of validateString that formats... validateString(path, 'paths[%s]', i);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly that's a good choice yes.


// Skip empty entries
if (path.length === 0) {
Expand Down Expand Up @@ -1254,7 +1261,9 @@ const posix = {

for (let i = args.length - 1; i >= 0 && !resolvedAbsolute; i--) {
const path = args[i];
validateString(path, `paths[${i}]`);
if (typeof path !== 'string') {
throw new ERR_INVALID_ARG_TYPE(`paths[${i}]`, 'string', path);
}

// Skip empty entries
if (path.length === 0) {
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-path-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ resolveTests.forEach(([resolve, tests]) => {
});
assert.strictEqual(failures.length, 0, failures.join('\n'));

for (const resolve of [path.posix.resolve, path.win32.resolve]) {
assert.throws(() => resolve('a', 1), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "paths[1]" argument must be of type string. ' +
'Received type number (1)',
});
}

if (common.isWindows) {
// Test resolving the current Windows drive letter from a spawned process.
// See https://github.com/nodejs/node/issues/7215
Expand Down
Loading