11'use strict' ;
22const { expectSpecifierMap } = require ( './helpers/parsing.js' ) ;
3- const { BUILT_IN_MODULE_SCHEME } = require ( '../lib/utils.js' ) ;
43
54describe ( 'Relative URL-like addresses' , ( ) => {
65 it ( 'should accept strings prefixed with ./, ../, or /' , ( ) => {
@@ -12,9 +11,9 @@ describe('Relative URL-like addresses', () => {
1211 }` ,
1312 'https://base.example/path1/path2/path3' ,
1413 {
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' )
1817 }
1918 ) ;
2019 } ) ;
@@ -28,9 +27,6 @@ describe('Relative URL-like addresses', () => {
2827 }` ,
2928 'data:text/html,test' ,
3029 {
31- dotSlash : [ ] ,
32- dotDotSlash : [ ] ,
33- slash : [ ]
3430 } ,
3531 [
3632 `Invalid address "./foo" for the specifier key "dotSlash".` ,
@@ -49,9 +45,9 @@ describe('Relative URL-like addresses', () => {
4945 }` ,
5046 'https://base.example/path1/path2/path3' ,
5147 {
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/' )
5551 }
5652 ) ;
5753 } ) ;
@@ -69,13 +65,6 @@ describe('Relative URL-like addresses', () => {
6965 }` ,
7066 'https://base.example/path1/path2/path3' ,
7167 {
72- dotSlash1 : [ ] ,
73- dotDotSlash1 : [ ] ,
74- dotSlash2 : [ ] ,
75- dotDotSlash2 : [ ] ,
76- slash2 : [ ] ,
77- dotSlash3 : [ ] ,
78- dotDotSlash3 : [ ]
7968 } ,
8069 [
8170 `Invalid address "%2E/" for the specifier key "dotSlash1".` ,
@@ -90,49 +79,6 @@ describe('Relative URL-like addresses', () => {
9079 } ) ;
9180} ) ;
9281
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-
13682describe ( 'Absolute URL addresses' , ( ) => {
13783 it ( 'should only accept absolute URL addresses with fetch schemes' , ( ) => {
13884 expectSpecifierMap (
@@ -152,58 +98,14 @@ describe('Absolute URL addresses', () => {
15298 }` ,
15399 'https://base.example/path1/path2/path3' ,
154100 {
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/' )
207109 } ,
208110 [
209111 `Invalid address "import:bad" for the specifier key "import".` ,
@@ -228,45 +130,11 @@ describe('Absolute URL addresses', () => {
228130 }` ,
229131 'https://base.example/path1/path2/path3' ,
230132 {
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' )
270138 } ,
271139 [
272140 `Invalid address "https://ex ample.org/" for the specifier key "unparseable1".` ,
@@ -281,54 +149,12 @@ describe('Failing addresses: mismatched trailing slashes', () => {
281149 it ( 'should warn for the simple case' , ( ) => {
282150 expectSpecifierMap (
283151 `{
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"
322153 }` ,
323154 'https://base.example/path1/path2/path3' ,
324155 {
325- 'trailer/' : [ expect . toMatchURL ( 'https://base.example/atrailer/' ) ] ,
326- [ `${ BUILT_IN_MODULE_SCHEME } :trailer/` ] : [ expect . toMatchURL ( 'https://base.example/bim-atrailer/' ) ]
327156 } ,
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 "/".` ]
332158 ) ;
333159 } ) ;
334160} ) ;
@@ -342,7 +168,6 @@ describe('Other invalid addresses', () => {
342168 }` ,
343169 'https://base.example/path1/path2/path3' ,
344170 {
345- foo : [ ]
346171 } ,
347172 [ `Invalid address "${ bad } " for the specifier key "foo".` ]
348173 ) ;
0 commit comments