1
1
'use strict' ;
2
2
const { expectSpecifierMap } = require ( './helpers/parsing.js' ) ;
3
- const { BUILT_IN_MODULE_SCHEME } = require ( '../lib/utils.js' ) ;
4
3
5
4
describe ( 'Relative URL-like addresses' , ( ) => {
6
5
it ( 'should accept strings prefixed with ./, ../, or /' , ( ) => {
@@ -12,9 +11,9 @@ describe('Relative URL-like addresses', () => {
12
11
}` ,
13
12
'https://base.example/path1/path2/path3' ,
14
13
{
15
- dotSlash : [ expect . toMatchURL ( 'https://base.example/path1/path2/foo' ) ] ,
16
- dotDotSlash : [ expect . toMatchURL ( 'https://base.example/path1/foo' ) ] ,
17
- slash : [ expect . toMatchURL ( 'https://base.example/foo' ) ]
14
+ dotSlash : expect . toMatchURL ( 'https://base.example/path1/path2/foo' ) ,
15
+ dotDotSlash : expect . toMatchURL ( 'https://base.example/path1/foo' ) ,
16
+ slash : expect . toMatchURL ( 'https://base.example/foo' )
18
17
}
19
18
) ;
20
19
} ) ;
@@ -28,9 +27,6 @@ describe('Relative URL-like addresses', () => {
28
27
}` ,
29
28
'data:text/html,test' ,
30
29
{
31
- dotSlash : [ ] ,
32
- dotDotSlash : [ ] ,
33
- slash : [ ]
34
30
} ,
35
31
[
36
32
`Invalid address "./foo" for the specifier key "dotSlash".` ,
@@ -49,9 +45,9 @@ describe('Relative URL-like addresses', () => {
49
45
}` ,
50
46
'https://base.example/path1/path2/path3' ,
51
47
{
52
- dotSlash : [ expect . toMatchURL ( 'https://base.example/path1/path2/' ) ] ,
53
- dotDotSlash : [ expect . toMatchURL ( 'https://base.example/path1/' ) ] ,
54
- slash : [ expect . toMatchURL ( 'https://base.example/' ) ]
48
+ dotSlash : expect . toMatchURL ( 'https://base.example/path1/path2/' ) ,
49
+ dotDotSlash : expect . toMatchURL ( 'https://base.example/path1/' ) ,
50
+ slash : expect . toMatchURL ( 'https://base.example/' )
55
51
}
56
52
) ;
57
53
} ) ;
@@ -69,13 +65,6 @@ describe('Relative URL-like addresses', () => {
69
65
}` ,
70
66
'https://base.example/path1/path2/path3' ,
71
67
{
72
- dotSlash1 : [ ] ,
73
- dotDotSlash1 : [ ] ,
74
- dotSlash2 : [ ] ,
75
- dotDotSlash2 : [ ] ,
76
- slash2 : [ ] ,
77
- dotSlash3 : [ ] ,
78
- dotDotSlash3 : [ ]
79
68
} ,
80
69
[
81
70
`Invalid address "%2E/" for the specifier key "dotSlash1".` ,
@@ -90,49 +79,6 @@ describe('Relative URL-like addresses', () => {
90
79
} ) ;
91
80
} ) ;
92
81
93
- describe ( 'Built-in module addresses' , ( ) => {
94
- it ( 'should accept URLs using the built-in module scheme' , ( ) => {
95
- expectSpecifierMap (
96
- `{
97
- "foo": "${ BUILT_IN_MODULE_SCHEME } :foo"
98
- }` ,
99
- 'https://base.example/path1/path2/path3' ,
100
- {
101
- foo : [ expect . toMatchURL ( `${ BUILT_IN_MODULE_SCHEME } :foo` ) ]
102
- }
103
- ) ;
104
- } ) ;
105
-
106
- it ( 'should ignore percent-encoded variants of the built-in module scheme' , ( ) => {
107
- expectSpecifierMap (
108
- `{
109
- "foo": "${ encodeURIComponent ( BUILT_IN_MODULE_SCHEME + ':' ) } foo"
110
- }` ,
111
- 'https://base.example/path1/path2/path3' ,
112
- {
113
- foo : [ ]
114
- } ,
115
- [ `Invalid address "${ encodeURIComponent ( BUILT_IN_MODULE_SCHEME + ':' ) } foo" for the specifier key "foo".` ]
116
- ) ;
117
- } ) ;
118
-
119
- it ( 'should allow built-in module URLs that contain "/" or "\\"' , ( ) => {
120
- expectSpecifierMap (
121
- `{
122
- "slashEnd": "${ BUILT_IN_MODULE_SCHEME } :foo/",
123
- "slashMiddle": "${ BUILT_IN_MODULE_SCHEME } :foo/bar",
124
- "backslash": "${ BUILT_IN_MODULE_SCHEME } :foo\\\\baz"
125
- }` ,
126
- 'https://base.example/path1/path2/path3' ,
127
- {
128
- slashEnd : [ expect . toMatchURL ( `${ BUILT_IN_MODULE_SCHEME } :foo/` ) ] ,
129
- slashMiddle : [ expect . toMatchURL ( `${ BUILT_IN_MODULE_SCHEME } :foo/bar` ) ] ,
130
- backslash : [ expect . toMatchURL ( `${ BUILT_IN_MODULE_SCHEME } :foo\\baz` ) ]
131
- }
132
- ) ;
133
- } ) ;
134
- } ) ;
135
-
136
82
describe ( 'Absolute URL addresses' , ( ) => {
137
83
it ( 'should only accept absolute URL addresses with fetch schemes' , ( ) => {
138
84
expectSpecifierMap (
@@ -152,58 +98,14 @@ describe('Absolute URL addresses', () => {
152
98
}` ,
153
99
'https://base.example/path1/path2/path3' ,
154
100
{
155
- about : [ expect . toMatchURL ( 'about:good' ) ] ,
156
- blob : [ expect . toMatchURL ( 'blob:good' ) ] ,
157
- data : [ expect . toMatchURL ( 'data:good' ) ] ,
158
- file : [ expect . toMatchURL ( 'file:///good' ) ] ,
159
- filesystem : [ expect . toMatchURL ( 'filesystem:good' ) ] ,
160
- http : [ expect . toMatchURL ( 'http://good/' ) ] ,
161
- https : [ expect . toMatchURL ( 'https://good/' ) ] ,
162
- ftp : [ expect . toMatchURL ( 'ftp://good/' ) ] ,
163
- import : [ ] ,
164
- mailto : [ ] ,
165
- javascript : [ ] ,
166
- wss : [ ]
167
- } ,
168
- [
169
- `Invalid address "import:bad" for the specifier key "import".` ,
170
- `Invalid address "mailto:bad" for the specifier key "mailto".` ,
171
- `Invalid address "javascript:bad" for the specifier key "javascript".` ,
172
- `Invalid address "wss:bad" for the specifier key "wss".`
173
- ]
174
- ) ;
175
- } ) ;
176
-
177
- it ( 'should only accept absolute URL addresses with fetch schemes inside arrays' , ( ) => {
178
- expectSpecifierMap (
179
- `{
180
- "about": ["about:good"],
181
- "blob": ["blob:good"],
182
- "data": ["data:good"],
183
- "file": ["file:///good"],
184
- "filesystem": ["filesystem:good"],
185
- "http": ["http://good/"],
186
- "https": ["https://good/"],
187
- "ftp": ["ftp://good/"],
188
- "import": ["import:bad"],
189
- "mailto": ["mailto:bad"],
190
- "javascript": ["javascript:bad"],
191
- "wss": ["wss:bad"]
192
- }` ,
193
- 'https://base.example/path1/path2/path3' ,
194
- {
195
- about : [ expect . toMatchURL ( 'about:good' ) ] ,
196
- blob : [ expect . toMatchURL ( 'blob:good' ) ] ,
197
- data : [ expect . toMatchURL ( 'data:good' ) ] ,
198
- file : [ expect . toMatchURL ( 'file:///good' ) ] ,
199
- filesystem : [ expect . toMatchURL ( 'filesystem:good' ) ] ,
200
- http : [ expect . toMatchURL ( 'http://good/' ) ] ,
201
- https : [ expect . toMatchURL ( 'https://good/' ) ] ,
202
- ftp : [ expect . toMatchURL ( 'ftp://good/' ) ] ,
203
- import : [ ] ,
204
- mailto : [ ] ,
205
- javascript : [ ] ,
206
- wss : [ ]
101
+ about : expect . toMatchURL ( 'about:good' ) ,
102
+ blob : expect . toMatchURL ( 'blob:good' ) ,
103
+ data : expect . toMatchURL ( 'data:good' ) ,
104
+ file : expect . toMatchURL ( 'file:///good' ) ,
105
+ filesystem : expect . toMatchURL ( 'filesystem:good' ) ,
106
+ http : expect . toMatchURL ( 'http://good/' ) ,
107
+ https : expect . toMatchURL ( 'https://good/' ) ,
108
+ ftp : expect . toMatchURL ( 'ftp://good/' )
207
109
} ,
208
110
[
209
111
`Invalid address "import:bad" for the specifier key "import".` ,
@@ -228,45 +130,11 @@ describe('Absolute URL addresses', () => {
228
130
}` ,
229
131
'https://base.example/path1/path2/path3' ,
230
132
{
231
- unparseable1 : [ ] ,
232
- unparseable2 : [ ] ,
233
- unparseable3 : [ ] ,
234
- invalidButParseable1 : [ expect . toMatchURL ( 'https://example.org/' ) ] ,
235
- invalidButParseable2 : [ expect . toMatchURL ( 'https://example.com///' ) ] ,
236
- prettyNormal : [ expect . toMatchURL ( 'https://example.net/' ) ] ,
237
- percentDecoding : [ expect . toMatchURL ( 'https://example.com/' ) ] ,
238
- noPercentDecoding : [ expect . toMatchURL ( 'https://example.com/%41' ) ]
239
- } ,
240
- [
241
- `Invalid address "https://ex ample.org/" for the specifier key "unparseable1".` ,
242
- `Invalid address "https://example.com:demo" for the specifier key "unparseable2".` ,
243
- `Invalid address "http://[www.example.com]/" for the specifier key "unparseable3".`
244
- ]
245
- ) ;
246
- } ) ;
247
-
248
- it ( 'should parse absolute URLs, ignoring unparseable ones inside arrays' , ( ) => {
249
- expectSpecifierMap (
250
- `{
251
- "unparseable1": ["https://ex ample.org/"],
252
- "unparseable2": ["https://example.com:demo"],
253
- "unparseable3": ["http://[www.example.com]/"],
254
- "invalidButParseable1": ["https:example.org"],
255
- "invalidButParseable2": ["https://///example.com///"],
256
- "prettyNormal": ["https://example.net"],
257
- "percentDecoding": ["https://ex%41mple.com/"],
258
- "noPercentDecoding": ["https://example.com/%41"]
259
- }` ,
260
- 'https://base.example/path1/path2/path3' ,
261
- {
262
- unparseable1 : [ ] ,
263
- unparseable2 : [ ] ,
264
- unparseable3 : [ ] ,
265
- invalidButParseable1 : [ expect . toMatchURL ( 'https://example.org/' ) ] ,
266
- invalidButParseable2 : [ expect . toMatchURL ( 'https://example.com///' ) ] ,
267
- prettyNormal : [ expect . toMatchURL ( 'https://example.net/' ) ] ,
268
- percentDecoding : [ expect . toMatchURL ( 'https://example.com/' ) ] ,
269
- noPercentDecoding : [ expect . toMatchURL ( 'https://example.com/%41' ) ]
133
+ invalidButParseable1 : expect . toMatchURL ( 'https://example.org/' ) ,
134
+ invalidButParseable2 : expect . toMatchURL ( 'https://example.com///' ) ,
135
+ prettyNormal : expect . toMatchURL ( 'https://example.net/' ) ,
136
+ percentDecoding : expect . toMatchURL ( 'https://example.com/' ) ,
137
+ noPercentDecoding : expect . toMatchURL ( 'https://example.com/%41' )
270
138
} ,
271
139
[
272
140
`Invalid address "https://ex ample.org/" for the specifier key "unparseable1".` ,
@@ -281,54 +149,12 @@ describe('Failing addresses: mismatched trailing slashes', () => {
281
149
it ( 'should warn for the simple case' , ( ) => {
282
150
expectSpecifierMap (
283
151
`{
284
- "trailer/": "/notrailer",
285
- "${ BUILT_IN_MODULE_SCHEME } :trailer/": "/bim-notrailer"
286
- }` ,
287
- 'https://base.example/path1/path2/path3' ,
288
- {
289
- 'trailer/' : [ ] ,
290
- [ `${ BUILT_IN_MODULE_SCHEME } :trailer/` ] : [ ]
291
- } ,
292
- [
293
- `Invalid address "https://base.example/notrailer" for package specifier key "trailer/". Package addresses must end with "/".` ,
294
- `Invalid address "https://base.example/bim-notrailer" for package specifier key "${ BUILT_IN_MODULE_SCHEME } :trailer/". Package addresses must end with "/".`
295
- ]
296
- ) ;
297
- } ) ;
298
-
299
- it ( 'should warn for a mismatch alone in an array' , ( ) => {
300
- expectSpecifierMap (
301
- `{
302
- "trailer/": ["/notrailer"],
303
- "${ BUILT_IN_MODULE_SCHEME } :trailer/": ["/bim-notrailer"]
304
- }` ,
305
- 'https://base.example/path1/path2/path3' ,
306
- {
307
- 'trailer/' : [ ] ,
308
- [ `${ BUILT_IN_MODULE_SCHEME } :trailer/` ] : [ ]
309
- } ,
310
- [
311
- `Invalid address "https://base.example/notrailer" for package specifier key "trailer/". Package addresses must end with "/".` ,
312
- `Invalid address "https://base.example/bim-notrailer" for package specifier key "${ BUILT_IN_MODULE_SCHEME } :trailer/". Package addresses must end with "/".`
313
- ]
314
- ) ;
315
- } ) ;
316
-
317
- it ( 'should warn for a mismatch alongside non-mismatches in an array' , ( ) => {
318
- expectSpecifierMap (
319
- `{
320
- "trailer/": ["/atrailer/", "/notrailer"],
321
- "${ BUILT_IN_MODULE_SCHEME } :trailer/": ["/bim-atrailer/", "/bim-notrailer"]
152
+ "trailer/": "/notrailer"
322
153
}` ,
323
154
'https://base.example/path1/path2/path3' ,
324
155
{
325
- 'trailer/' : [ expect . toMatchURL ( 'https://base.example/atrailer/' ) ] ,
326
- [ `${ BUILT_IN_MODULE_SCHEME } :trailer/` ] : [ expect . toMatchURL ( 'https://base.example/bim-atrailer/' ) ]
327
156
} ,
328
- [
329
- `Invalid address "https://base.example/notrailer" for package specifier key "trailer/". Package addresses must end with "/".` ,
330
- `Invalid address "https://base.example/bim-notrailer" for package specifier key "${ BUILT_IN_MODULE_SCHEME } :trailer/". Package addresses must end with "/".`
331
- ]
157
+ [ `Invalid address "https://base.example/notrailer" for package specifier key "trailer/". Package addresses must end with "/".` ]
332
158
) ;
333
159
} ) ;
334
160
} ) ;
@@ -342,7 +168,6 @@ describe('Other invalid addresses', () => {
342
168
}` ,
343
169
'https://base.example/path1/path2/path3' ,
344
170
{
345
- foo : [ ]
346
171
} ,
347
172
[ `Invalid address "${ bad } " for the specifier key "foo".` ]
348
173
) ;
0 commit comments