Skip to content

Commit 875c813

Browse files
committed
test: add more test cases for pathToFileURL
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
1 parent bf7e79c commit 875c813

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

test/parallel/test-url-pathtofileurl.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,24 @@ const url = require('url');
2222
}
2323

2424
{
25-
assert.throws(() => {
26-
url.pathToFileURL('\\\\exa mple\\share\\file.txt', { windows: true });
27-
}, {
28-
code: 'ERR_INVALID_URL',
29-
});
25+
const forbiddenHostnameChars = [
26+
'\\\\exa mple\\share\\file.txt',
27+
'\\\\host name\\share\\file.txt', // space
28+
'\\\\host#name\\share\\file.txt', // hash
29+
'\\\\host?name\\share\\file.txt', // question mark
30+
'\\\\host@name\\share\\file.txt', // at sign
31+
'\\\\host:name\\share\\file.txt', // colon
32+
'\\\\host/name\\share\\file.txt', // forward slash
33+
'\\\\host[name\\share\\file.txt', // left bracket
34+
'\\\\host]name\\share\\file.txt', // right bracket
35+
];
36+
for (const path of forbiddenHostnameChars) {
37+
assert.throws(() => {
38+
url.pathToFileURL(path, { windows: true });
39+
}, {
40+
code: 'ERR_INVALID_URL',
41+
}, `pathToFileURL('${path}') should throw ERR_INVALID_URL`);
42+
}
3043
}
3144

3245
{

0 commit comments

Comments
 (0)