Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 649d767

Browse filesBrowse files
aduh95RafaelGSS
authored andcommitted
test: increase coverage of pathToFileURL
PR-URL: #55493 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
1 parent f00ad27 commit 649d767
Copy full SHA for 649d767

File tree

Expand file treeCollapse file tree

1 file changed

+26
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-0
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-url-pathtofileurl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-url-pathtofileurl.js
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const windowsTestCases = [
114114
// Extended UNC path
115115
{ path: '\\\\?\\UNC\\server\\share\\folder\\file.txt', expected: 'file://server/share/folder/file.txt' },
116116
];
117+
const alphabet = String.fromCharCode(...Array.from({ length: 26 }, (_, i) => 'a'.charCodeAt() + i));
117118
const posixTestCases = [
118119
// Lowercase ascii alpha
119120
{ path: '/foo', expected: 'file:///foo' },
@@ -159,6 +160,31 @@ const posixTestCases = [
159160
{ path: '/🚀', expected: 'file:///%F0%9F%9A%80' },
160161
// "unsafe" chars
161162
{ 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' },
163+
// All of the 16-bit UTF-16 chars
164+
{
165+
path: `/${Array.from({ length: 0x7FFF }, (_, i) => String.fromCharCode(i)).join('')}`,
166+
expected: `file:///${
167+
Array.from({ length: 0x21 }, (_, i) => `%${i.toString(16).toUpperCase().padStart(2, '0')}`).join('')
168+
}!%22%23$%25&'()*+,-./0123456789:;%3C=%3E%3F@${
169+
alphabet.toUpperCase()
170+
}%5B%5C%5D%5E_%60${alphabet}%7B%7C%7D%7E%7F${
171+
Array.from({ length: 0x800 - 0x80 }, (_, i) => `%${
172+
(Math.floor((i - 0x80) / 0x40) + 0xC4).toString(16).toUpperCase()
173+
}%${
174+
((i % 0x40) + 0x80).toString(16).toUpperCase()
175+
}`).join('')
176+
}${
177+
Array.from({ length: 0x7FFF - 0x800 }, (_, i) => i + 0x800).map((i) => `%E${
178+
(i >> 12).toString(16).toUpperCase()
179+
}%${
180+
(((i >> 6) % 0x40) + 0x80).toString(16).toUpperCase()
181+
}%${
182+
((i % 0x40) + 0x80).toString(16).toUpperCase()
183+
}`).join('')
184+
}`
185+
},
186+
// Trying with some pair of 16-bit surrogate pseudo-characters
187+
{ path: `/${String.fromCodePoint(0x1F303)}`, expected: 'file:///%F0%9F%8C%83' },
162188
];
163189

164190
for (const { path, expected } of windowsTestCases) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.