-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
relative-url-style.mjs
79 lines (76 loc) · 2.32 KB
/
relative-url-style.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* eslint-disable no-template-curly-in-string */
import {getTester} from './utils/test.mjs';
const {test} = getTester(import.meta);
test.snapshot({
valid: [
'URL("./foo", base)',
'new URL(...["./foo"], base)',
'new URL(["./foo"], base)',
'new URL("./foo")',
'new URL("./foo", base, extra)',
'new URL("./foo", ...[base])',
'new NOT_URL("./foo", base)',
'new NOT_URL("./", base)',
'new URL("./", base)',
'new URL("./", "https://example.com/a/b/c.html")',
'const base = new URL("./", import.meta.url)',
'new URL',
'new URL(0, base)',
// Not checking this case
'new globalThis.URL("./foo", base)',
'const foo = "./foo"; new URL(foo, base)',
'const foo = "/foo"; new URL(`.${foo}`, base)',
'new URL(`.${foo}`, base)',
'new URL(".", base)',
'new URL(".././foo", base)',
// We don't check cooked value
'new URL(`\\u002E/${foo}`, base)',
// We don't check escaped string
'new URL("\\u002E/foo", base)',
'new URL(\'\\u002E/foo\', base)',
],
invalid: [
'new URL("./foo", base)',
'new URL(\'./foo\', base)',
'new URL("././a", base)',
'new URL(`./${foo}`, base)',
'new URL("./", "https://example.com/a/b/")',
],
});
const alwaysAddDotSlashOptions = ['always'];
test.snapshot({
valid: [
'URL("foo", base)',
'new URL(...["foo"], base)',
'new URL(["foo"], base)',
'new URL("foo")',
'new URL("foo", base, extra)',
'new URL("foo", ...[base])',
'new NOT_URL("foo", base)',
'new URL("", base)',
'new URL("", "https://example.com/a/b.html")',
'/* 2 */ new URL',
'new URL(0, base2)',
// Not checking this case
'new globalThis.URL("foo", base)',
'new URL(`${foo}`, base2)',
'new URL(`.${foo}`, base2)',
'new URL(".", base2)',
'new URL("//example.org", "https://example.com")',
'new URL("//example.org", "ftp://example.com")',
'new URL("ftp://example.org", "https://example.com")',
'new URL("https://example.org:65536", "https://example.com")',
'new URL("/", base)',
'new URL("/foo", base)',
'new URL("../foo", base)',
'new URL(".././foo", base)',
'new URL("C:\\foo", base)',
'new URL("\\u002E/foo", base)',
'new URL("\\u002Ffoo", base)',
].map(code => ({code, options: alwaysAddDotSlashOptions})),
invalid: [
'new URL("foo", base)',
'new URL(\'foo\', base)',
'new URL("", "https://example.com/a/b/")',
].map(code => ({code, options: alwaysAddDotSlashOptions})),
});