@@ -22,3 +22,103 @@ const url = require('url');
22
22
const fileURL = url . pathToFileURL ( 'test/%' ) . href ;
23
23
assert . ok ( fileURL . includes ( '%25' ) ) ;
24
24
}
25
+
26
+ {
27
+ let testCases ;
28
+ if ( isWindows ) {
29
+ testCases = [
30
+ // lowercase ascii alpha
31
+ { path : 'C:\\foo' , expected : 'file:///C:/foo' } ,
32
+ // uppercase ascii alpha
33
+ { path : 'C:\\FOO' , expected : 'file:///C:/FOO' } ,
34
+ // dir
35
+ { path : 'C:\\dir\\foo' , expected : 'file:///C:/dir/foo' } ,
36
+ // trailing separator
37
+ { path : 'C:\\dir\\' , expected : 'file:///C:/dir/' } ,
38
+ // dot
39
+ { path : 'C:\\foo.mjs' , expected : 'file:///C:/foo.mjs' } ,
40
+ // space
41
+ { path : 'C:\\foo bar' , expected : 'file:///C:/foo%20bar' } ,
42
+ // question mark
43
+ { path : 'C:\\foo?bar' , expected : 'file:///C:/foo%3Fbar' } ,
44
+ // number sign
45
+ { path : 'C:\\foo#bar' , expected : 'file:///C:/foo%23bar' } ,
46
+ // ampersand
47
+ { path : 'C:\\foo&bar' , expected : 'file:///C:/foo&bar' } ,
48
+ // equals
49
+ { path : 'C:\\foo=bar' , expected : 'file:///C:/foo=bar' } ,
50
+ // colon
51
+ { path : 'C:\\foo:bar' , expected : 'file:///C:/foo:bar' } ,
52
+ // semicolon
53
+ { path : 'C:\\foo;bar' , expected : 'file:///C:/foo;bar' } ,
54
+ // percent
55
+ { path : 'C:\\foo%bar' , expected : 'file:///C:/foo%25bar' } ,
56
+ // backslash
57
+ { path : 'C:\\foo\\bar' , expected : 'file:///C:/foo/bar' } ,
58
+ // backspace
59
+ { path : 'C:\\foo\bbar' , expected : 'file:///C:/foo%08bar' } ,
60
+ // tab
61
+ { path : 'C:\\foo\tbar' , expected : 'file:///C:/foo%09bar' } ,
62
+ // newline
63
+ { path : 'C:\\foo\nbar' , expected : 'file:///C:/foo%0Abar' } ,
64
+ // carriage return
65
+ { path : 'C:\\foo\rbar' , expected : 'file:///C:/foo%0Dbar' } ,
66
+ // latin1
67
+ { path : 'C:\\fóóbàr' , expected : 'file:///C:/f%C3%B3%C3%B3b%C3%A0r' } ,
68
+ // euro sign (BMP code point)
69
+ { path : 'C:\\€' , expected : 'file:///C:/%E2%82%AC' } ,
70
+ // rocket emoji (non-BMP code point)
71
+ { path : 'C:\\🚀' , expected : 'file:///C:/%F0%9F%9A%80' }
72
+ ] ;
73
+ } else {
74
+ testCases = [
75
+ // lowercase ascii alpha
76
+ { path : '/foo' , expected : 'file:///foo' } ,
77
+ // uppercase ascii alpha
78
+ { path : '/FOO' , expected : 'file:///FOO' } ,
79
+ // dir
80
+ { path : '/dir/foo' , expected : 'file:///dir/foo' } ,
81
+ // trailing separator
82
+ { path : '/dir/' , expected : 'file:///dir/' } ,
83
+ // dot
84
+ { path : '/foo.mjs' , expected : 'file:///foo.mjs' } ,
85
+ // space
86
+ { path : '/foo bar' , expected : 'file:///foo%20bar' } ,
87
+ // question mark
88
+ { path : '/foo?bar' , expected : 'file:///foo%3Fbar' } ,
89
+ // number sign
90
+ { path : '/foo#bar' , expected : 'file:///foo%23bar' } ,
91
+ // ampersand
92
+ { path : '/foo&bar' , expected : 'file:///foo&bar' } ,
93
+ // equals
94
+ { path : '/foo=bar' , expected : 'file:///foo=bar' } ,
95
+ // colon
96
+ { path : '/foo:bar' , expected : 'file:///foo:bar' } ,
97
+ // semicolon
98
+ { path : '/foo;bar' , expected : 'file:///foo;bar' } ,
99
+ // percent
100
+ { path : '/foo%bar' , expected : 'file:///foo%25bar' } ,
101
+ // backslash
102
+ { path : '/foo\\bar' , expected : 'file:///foo%5Cbar' } ,
103
+ // backspace
104
+ { path : '/foo\bbar' , expected : 'file:///foo%08bar' } ,
105
+ // tab
106
+ { path : '/foo\tbar' , expected : 'file:///foo%09bar' } ,
107
+ // newline
108
+ { path : '/foo\nbar' , expected : 'file:///foo%0Abar' } ,
109
+ // carriage return
110
+ { path : '/foo\rbar' , expected : 'file:///foo%0Dbar' } ,
111
+ // latin1
112
+ { path : '/fóóbàr' , expected : 'file:///f%C3%B3%C3%B3b%C3%A0r' } ,
113
+ // euro sign (BMP code point)
114
+ { path : '/€' , expected : 'file:///%E2%82%AC' } ,
115
+ // rocket emoji (non-BMP code point)
116
+ { path : '/🚀' , expected : 'file:///%F0%9F%9A%80' } ,
117
+ ] ;
118
+ }
119
+
120
+ for ( const { path, expected } of testCases ) {
121
+ const actual = url . pathToFileURL ( path ) . href ;
122
+ assert . strictEqual ( actual , expected ) ;
123
+ }
124
+ }
0 commit comments