Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase coverage of pathToFileURL #55493

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions test/parallel/test-url-pathtofileurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const windowsTestCases = [
// Extended UNC path
{ path: '\\\\?\\UNC\\server\\share\\folder\\file.txt', expected: 'file://server/share/folder/file.txt' },
];
const alphabet = String.fromCharCode(...Array.from({ length: 26 }, (_, i) => 'a'.charCodeAt() + i));
const posixTestCases = [
// Lowercase ascii alpha
{ path: '/foo', expected: 'file:///foo' },
Expand Down Expand Up @@ -159,6 +160,31 @@ const posixTestCases = [
{ path: '/🚀', expected: 'file:///%F0%9F%9A%80' },
// "unsafe" chars
{ path: '/foo\r\n\t<>"#%{}|^[\\~]`?bar', expected: 'file:///foo%0D%0A%09%3C%3E%22%23%25%7B%7D%7C%5E%5B%5C%7E%5D%60%3Fbar' },
// All of the 16-bit UTF-16 chars
{
path: `/${String.fromCharCode(...Array.from({ length: 0x7FFF }, (_, i) => i))}`,
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
expected: `file:///${
Array.from({ length: 0x21 }, (_, i) => `%${i.toString(16).toUpperCase().padStart(2, '0')}`).join('')
}!%22%23$%25&'()*+,-./0123456789:;%3C=%3E%3F@${
alphabet.toUpperCase()
}%5B%5C%5D%5E_%60${alphabet}%7B%7C%7D%7E%7F${
Array.from({ length: 0x800 - 0x80 }, (_, i) => `%${
(Math.floor((i - 0x80) / 0x40) + 0xC4).toString(16).toUpperCase()
}%${
((i % 0x40) + 0x80).toString(16).toUpperCase()
}`).join('')
}${
Array.from({ length: 0x7FFF - 0x800 }, (_, i) => i + 0x800).map((i) => `%E${
(i >> 12).toString(16).toUpperCase()
}%${
(((i >> 6) % 0x40) + 0x80).toString(16).toUpperCase()
}%${
((i % 0x40) + 0x80).toString(16).toUpperCase()
}`).join('')
}`
},
// Trying with some pair of 16-bit surrogate pseudo-characters
{ path: `/${String.fromCodePoint(0x1F303)}`, expected: 'file:///%F0%9F%8C%83' },
];

for (const { path, expected } of windowsTestCases) {
Expand Down
Loading