Skip to content
Open
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
23 changes: 18 additions & 5 deletions test/parallel/test-url-pathtofileurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@
}

{
assert.throws(() => {
url.pathToFileURL('\\\\exa mple\\share\\file.txt', { windows: true });
}, {
code: 'ERR_INVALID_URL',
});
const forbiddenHostnameChars = [
'\\\\exa mple\\share\\file.txt',
'\\\\host name\\share\\file.txt', // space
'\\\\host#name\\share\\file.txt', // hash
'\\\\host?name\\share\\file.txt', // question mark
'\\\\host@name\\share\\file.txt', // at sign
'\\\\host:name\\share\\file.txt', // colon
'\\\\host/name\\share\\file.txt', // forward slash
'\\\\host[name\\share\\file.txt', // left bracket
'\\\\host]name\\share\\file.txt', // right bracket
];
Comment on lines +25 to +35
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to https://url.spec.whatwg.org/#host-miscellaneous, there are a few more forbidden char we might as well check for:

Suggested change
const forbiddenHostnameChars = [
'\\\\exa mple\\share\\file.txt',
'\\\\host name\\share\\file.txt', // space
'\\\\host#name\\share\\file.txt', // hash
'\\\\host?name\\share\\file.txt', // question mark
'\\\\host@name\\share\\file.txt', // at sign
'\\\\host:name\\share\\file.txt', // colon
'\\\\host/name\\share\\file.txt', // forward slash
'\\\\host[name\\share\\file.txt', // left bracket
'\\\\host]name\\share\\file.txt', // right bracket
];
const forbiddenHostnameChars = Array.from('\0\t\n\r #:<>?@[]^|', (sep) => `\\\\host${sep}name\\share\\file.txt`);

But it looks like \n, \r, \t are ignored instead of being rejected; # and ? might have a special significant in UNC not sure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've opened ada-url/ada#1142 to address the # and ? cases

for (const path of forbiddenHostnameChars) {
assert.throws(() => {

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/node/node/node/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/node/node/node/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /Users/runner/work/node/node/node/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / aarch64-darwin: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/Users/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /Users/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / x86_64-linux: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / x86_64-darwin: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/Users/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /Users/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-3.0.19

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-1.1.1w

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-4.0.0

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-3.5.5

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared openssl-3.6.1

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js

Check failure on line 37 in test/parallel/test-url-pathtofileurl.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared boringssl-0.20260413.0

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Missing expected exception: pathToFileURL('\\host#name\share\file.txt') should throw ERR_INVALID_URL at Object.<anonymous> (/home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js:37:12) at Module._compile (node:internal/modules/cjs/loader:1873:14) at Object..js (node:internal/modules/cjs/loader:2013:10) at Module.load (node:internal/modules/cjs/loader:1596:32) at Module._load (node:internal/modules/cjs/loader:1398:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: { code: 'ERR_INVALID_URL' }, operator: 'throws', diff: 'simple' } Node.js v27.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v27.0.0-nightly2026-05-1309ca37faee-slim/test/parallel/test-url-pathtofileurl.js
url.pathToFileURL(path, { windows: true });
}, {
code: 'ERR_INVALID_URL',
}, `pathToFileURL('${path}') should throw ERR_INVALID_URL`);
}
}

{
Expand Down
Loading