@fedify/uri-template 2.0.0-pr.475.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +78 -0
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/ast.d.cts +39 -0
- package/dist/ast.d.ts +39 -0
- package/dist/compile.cjs +30 -0
- package/dist/compile.d.cts +80 -0
- package/dist/compile.d.ts +80 -0
- package/dist/compile.js +30 -0
- package/dist/error.cjs +29 -0
- package/dist/error.js +28 -0
- package/dist/expand.cjs +94 -0
- package/dist/expand.d.cts +72 -0
- package/dist/expand.d.ts +72 -0
- package/dist/expand.js +94 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/match.cjs +180 -0
- package/dist/match.d.cts +92 -0
- package/dist/match.d.ts +92 -0
- package/dist/match.js +180 -0
- package/dist/match.spec.cjs +109 -0
- package/dist/match.spec.d.cts +1 -0
- package/dist/match.spec.d.ts +1 -0
- package/dist/match.spec.js +108 -0
- package/dist/parser.cjs +102 -0
- package/dist/parser.d.cts +35 -0
- package/dist/parser.d.ts +35 -0
- package/dist/parser.js +102 -0
- package/dist/rfc6570.spec.cjs +419 -0
- package/dist/rfc6570.spec.d.cts +1 -0
- package/dist/rfc6570.spec.d.ts +1 -0
- package/dist/rfc6570.spec.js +418 -0
- package/dist/spec.cjs +112 -0
- package/dist/spec.js +108 -0
- package/package.json +60 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_compile = require('./compile.cjs');
|
|
3
|
+
const node_assert_strict = require_rolldown_runtime.__toESM(require("node:assert/strict"));
|
|
4
|
+
const node_test = require_rolldown_runtime.__toESM(require("node:test"));
|
|
5
|
+
|
|
6
|
+
//#region src/rfc6570.spec.ts
|
|
7
|
+
(0, node_test.describe)("basic expansion", () => {
|
|
8
|
+
(0, node_test.test)("scalar", () => {
|
|
9
|
+
const t = require_compile.compile("{var}");
|
|
10
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ var: "value" }), "value");
|
|
11
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ var: "va lue" }), "va%20lue");
|
|
12
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ var: "100%" }), "100%25");
|
|
13
|
+
});
|
|
14
|
+
(0, node_test.test)("list (no explode)", () => {
|
|
15
|
+
const t = require_compile.compile("{list}");
|
|
16
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ list: [
|
|
17
|
+
"red",
|
|
18
|
+
"green",
|
|
19
|
+
"blue"
|
|
20
|
+
] }), "red,green,blue");
|
|
21
|
+
});
|
|
22
|
+
(0, node_test.test)("map (no explode)", () => {
|
|
23
|
+
const t = require_compile.compile("{keys}");
|
|
24
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ keys: {
|
|
25
|
+
semi: ";",
|
|
26
|
+
dot: ".",
|
|
27
|
+
comma: ","
|
|
28
|
+
} }), "semi,%3B,dot,.,comma,%2C");
|
|
29
|
+
});
|
|
30
|
+
(0, node_test.test)("multiple vars", () => {
|
|
31
|
+
const t = require_compile.compile("{x,y}");
|
|
32
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ x: "1024" }), "1024");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
(0, node_test.describe)("{+var} reserved expansion", () => {
|
|
36
|
+
(0, node_test.test)("{+var} allows reserved - basic", () => {
|
|
37
|
+
const t = require_compile.compile("{+var}");
|
|
38
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ var: "value" }), "value");
|
|
39
|
+
});
|
|
40
|
+
(0, node_test.test)("{+var} allows reserved - percent encoding", () => {
|
|
41
|
+
const t = require_compile.compile("{+hello}");
|
|
42
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ hello: "Hello World!" }), "Hello%20World!");
|
|
43
|
+
});
|
|
44
|
+
(0, node_test.test)("{+var} allows reserved - already encoded", () => {
|
|
45
|
+
const t = require_compile.compile("{+half}");
|
|
46
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ half: "50%" }), "50%25");
|
|
47
|
+
});
|
|
48
|
+
(0, node_test.test)("{+var} allows reserved - base URL comparison", () => {
|
|
49
|
+
const t1 = require_compile.compile("{base}index");
|
|
50
|
+
const t2 = require_compile.compile("{+base}index");
|
|
51
|
+
const vars = { base: "http://example.com/home/" };
|
|
52
|
+
(0, node_assert_strict.deepStrictEqual)(t1.expand(vars), "http%3A%2F%2Fexample.com%2Fhome%2Findex");
|
|
53
|
+
(0, node_assert_strict.deepStrictEqual)(t2.expand(vars), "http://example.com/home/index");
|
|
54
|
+
});
|
|
55
|
+
(0, node_test.test)("{+var} allows reserved - empty value", () => {
|
|
56
|
+
const t = require_compile.compile("O{+empty}X");
|
|
57
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ empty: "" }), "OX");
|
|
58
|
+
});
|
|
59
|
+
(0, node_test.test)("{+var} allows reserved - undefined value", () => {
|
|
60
|
+
const t = require_compile.compile("O{+undef}X");
|
|
61
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ undef: void 0 }), "OX");
|
|
62
|
+
});
|
|
63
|
+
(0, node_test.test)("{+var} allows reserved - path", () => {
|
|
64
|
+
const t = require_compile.compile("{+path}");
|
|
65
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ path: "/foo/bar" }), "/foo/bar");
|
|
66
|
+
});
|
|
67
|
+
(0, node_test.test)("{+var} allows reserved - path appended", () => {
|
|
68
|
+
const t = require_compile.compile("{+path}/here");
|
|
69
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ path: "/foo/bar" }), "/foo/bar/here");
|
|
70
|
+
});
|
|
71
|
+
(0, node_test.test)("{+var} allows reserved - in query", () => {
|
|
72
|
+
const t = require_compile.compile("here?ref={+path}");
|
|
73
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ path: "/foo/bar" }), "here?ref=/foo/bar");
|
|
74
|
+
});
|
|
75
|
+
(0, node_test.test)("{+var} allows reserved - mixed with normal var", () => {
|
|
76
|
+
const t = require_compile.compile("up{+path}{var}/here");
|
|
77
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
78
|
+
path: "/foo/bar",
|
|
79
|
+
var: "value"
|
|
80
|
+
}), "up/foo/barvalue/here");
|
|
81
|
+
});
|
|
82
|
+
(0, node_test.test)("{+var} allows reserved - multiple vars", () => {
|
|
83
|
+
const t = require_compile.compile("{+x,hello,y}");
|
|
84
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
85
|
+
x: "1024",
|
|
86
|
+
hello: "Hello World!",
|
|
87
|
+
y: "768"
|
|
88
|
+
}), "1024,Hello%20World!,768");
|
|
89
|
+
});
|
|
90
|
+
(0, node_test.test)("{+var} allows reserved - multiple vars with path", () => {
|
|
91
|
+
const t = require_compile.compile("{+path,x}/here");
|
|
92
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
93
|
+
path: "/foo/bar",
|
|
94
|
+
x: "1024"
|
|
95
|
+
}), "/foo/bar,1024/here");
|
|
96
|
+
});
|
|
97
|
+
(0, node_test.test)("{+var} allows reserved - prefix modifier", () => {
|
|
98
|
+
const t = require_compile.compile("{+path:6}/here");
|
|
99
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ path: "/foo/bar" }), "/foo/b/here");
|
|
100
|
+
});
|
|
101
|
+
(0, node_test.test)("{+var} allows reserved - list", () => {
|
|
102
|
+
const t = require_compile.compile("{+list}");
|
|
103
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ list: [
|
|
104
|
+
"red",
|
|
105
|
+
"green",
|
|
106
|
+
"blue"
|
|
107
|
+
] }), "red,green,blue");
|
|
108
|
+
});
|
|
109
|
+
(0, node_test.test)("{+var} allows reserved - list explode", () => {
|
|
110
|
+
const t = require_compile.compile("{+list*}");
|
|
111
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ list: [
|
|
112
|
+
"red",
|
|
113
|
+
"green",
|
|
114
|
+
"blue"
|
|
115
|
+
] }), "red,green,blue");
|
|
116
|
+
});
|
|
117
|
+
(0, node_test.test)("{+var} allows reserved - map", () => {
|
|
118
|
+
const t = require_compile.compile("{+keys}");
|
|
119
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ keys: {
|
|
120
|
+
semi: ";",
|
|
121
|
+
dot: ".",
|
|
122
|
+
comma: ","
|
|
123
|
+
} }), "semi,;,dot,.,comma,,");
|
|
124
|
+
});
|
|
125
|
+
(0, node_test.test)("{+var} allows reserved - map explode", () => {
|
|
126
|
+
const t = require_compile.compile("{+keys*}");
|
|
127
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ keys: {
|
|
128
|
+
semi: ";",
|
|
129
|
+
dot: ".",
|
|
130
|
+
comma: ","
|
|
131
|
+
} }), "semi=;,dot=.,comma=,");
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
(0, node_test.describe)("{#var} fragment expansion", () => {
|
|
135
|
+
(0, node_test.test)("{#var} fragment", () => {
|
|
136
|
+
const t = require_compile.compile("{#frag}");
|
|
137
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ frag: "a b" }), "#a%20b");
|
|
138
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ frag: "a/b?c#d" }), "#a/b?c%23d");
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
(0, node_test.describe)("{.var} label expansion", () => {
|
|
142
|
+
(0, node_test.test)("{.var} label - basic", () => {
|
|
143
|
+
const t = require_compile.compile("www{.domain}");
|
|
144
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ domain: "example" }), "www.example");
|
|
145
|
+
});
|
|
146
|
+
(0, node_test.test)("{.var} label - single variable", () => {
|
|
147
|
+
const t = require_compile.compile("{.who}");
|
|
148
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ who: "fred" }), ".fred");
|
|
149
|
+
});
|
|
150
|
+
(0, node_test.test)("{.var} label - same variable twice", () => {
|
|
151
|
+
const t = require_compile.compile("{.who,who}");
|
|
152
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ who: "fred" }), ".fred.fred");
|
|
153
|
+
});
|
|
154
|
+
(0, node_test.test)("{.var} label - mixed variables with encoding", () => {
|
|
155
|
+
const t = require_compile.compile("{.half,who}");
|
|
156
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
157
|
+
half: "50%",
|
|
158
|
+
who: "fred"
|
|
159
|
+
}), ".50%25.fred");
|
|
160
|
+
});
|
|
161
|
+
(0, node_test.test)("{.var} label - explode with multiple labels", () => {
|
|
162
|
+
const t = require_compile.compile("www{.dom*}");
|
|
163
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ dom: ["example", "com"] }), "www.example.com");
|
|
164
|
+
});
|
|
165
|
+
(0, node_test.test)("{.var} label - with prefix", () => {
|
|
166
|
+
const t = require_compile.compile("X{.var}");
|
|
167
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ var: "value" }), "X.value");
|
|
168
|
+
});
|
|
169
|
+
(0, node_test.test)("{.var} label - empty value", () => {
|
|
170
|
+
const t = require_compile.compile("X{.empty}");
|
|
171
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ empty: "" }), "X.");
|
|
172
|
+
});
|
|
173
|
+
(0, node_test.test)("{.var} label - undefined value", () => {
|
|
174
|
+
const t = require_compile.compile("X{.undef}");
|
|
175
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ undef: void 0 }), "X");
|
|
176
|
+
});
|
|
177
|
+
(0, node_test.test)("{.var} label - prefix modifier", () => {
|
|
178
|
+
const t = require_compile.compile("X{.var:3}");
|
|
179
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ var: "value" }), "X.val");
|
|
180
|
+
});
|
|
181
|
+
(0, node_test.test)("{.var} label - list without explode", () => {
|
|
182
|
+
const t = require_compile.compile("X{.list}");
|
|
183
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ list: [
|
|
184
|
+
"red",
|
|
185
|
+
"green",
|
|
186
|
+
"blue"
|
|
187
|
+
] }), "X.red,green,blue");
|
|
188
|
+
});
|
|
189
|
+
(0, node_test.test)("{.var} label - list with explode", () => {
|
|
190
|
+
const t = require_compile.compile("X{.list*}");
|
|
191
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ list: [
|
|
192
|
+
"red",
|
|
193
|
+
"green",
|
|
194
|
+
"blue"
|
|
195
|
+
] }), "X.red.green.blue");
|
|
196
|
+
});
|
|
197
|
+
(0, node_test.test)("{.var} label - map without explode", () => {
|
|
198
|
+
const t = require_compile.compile("X{.keys}");
|
|
199
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ keys: {
|
|
200
|
+
semi: ";",
|
|
201
|
+
dot: ".",
|
|
202
|
+
comma: ","
|
|
203
|
+
} }), "X.semi,%3B,dot,.,comma,%2C");
|
|
204
|
+
});
|
|
205
|
+
(0, node_test.test)("{.var} label - map with explode", () => {
|
|
206
|
+
const t = require_compile.compile("X{.keys*}");
|
|
207
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ keys: {
|
|
208
|
+
semi: ";",
|
|
209
|
+
dot: ".",
|
|
210
|
+
comma: ","
|
|
211
|
+
} }), "X.semi=%3B.dot=..comma=%2C");
|
|
212
|
+
});
|
|
213
|
+
(0, node_test.test)("{.var} label - empty map without explode", () => {
|
|
214
|
+
const t = require_compile.compile("X{.empty_keys}");
|
|
215
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ empty_keys: {} }), "X");
|
|
216
|
+
});
|
|
217
|
+
(0, node_test.test)("{.var} label - empty map with explode", () => {
|
|
218
|
+
const t = require_compile.compile("X{.empty_keys*}");
|
|
219
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ empty_keys: {} }), "X");
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
(0, node_test.describe)("path and query operators", () => {
|
|
223
|
+
(0, node_test.test)("{/var} path segment", () => {
|
|
224
|
+
const t = require_compile.compile("/users{/id}");
|
|
225
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ id: "a/b" }), "/users/a%2Fb");
|
|
226
|
+
});
|
|
227
|
+
(0, node_test.test)("{;x,y} matrix params", () => {
|
|
228
|
+
const t = require_compile.compile("/res{;x,y}");
|
|
229
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
230
|
+
x: "a b",
|
|
231
|
+
y: ""
|
|
232
|
+
}), "/res;x=a%20b;y");
|
|
233
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
234
|
+
x: void 0,
|
|
235
|
+
y: void 0
|
|
236
|
+
}), "/res");
|
|
237
|
+
});
|
|
238
|
+
(0, node_test.test)("{?x,y} query", () => {
|
|
239
|
+
const t = require_compile.compile("/search{?q,lang}");
|
|
240
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
241
|
+
q: "a b",
|
|
242
|
+
lang: "en"
|
|
243
|
+
}), "/search?q=a%20b&lang=en");
|
|
244
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
245
|
+
q: "",
|
|
246
|
+
lang: void 0
|
|
247
|
+
}), "/search?q=");
|
|
248
|
+
});
|
|
249
|
+
(0, node_test.test)("{&x,y} query continuation", () => {
|
|
250
|
+
const t = require_compile.compile("/search?q=init{&x,y}");
|
|
251
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
252
|
+
x: "1",
|
|
253
|
+
y: "2"
|
|
254
|
+
}), "/search?q=init&x=1&y=2");
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
(0, node_test.describe)("explode modifier", () => {
|
|
258
|
+
(0, node_test.test)("explode list", () => {
|
|
259
|
+
const t = require_compile.compile("/tags{;tags*}");
|
|
260
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ tags: [
|
|
261
|
+
"red",
|
|
262
|
+
"green",
|
|
263
|
+
"blue"
|
|
264
|
+
] }), "/tags;tags=red;tags=green;tags=blue");
|
|
265
|
+
});
|
|
266
|
+
(0, node_test.test)("explode map", () => {
|
|
267
|
+
const t = require_compile.compile("{?keys*}");
|
|
268
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ keys: {
|
|
269
|
+
semi: ";",
|
|
270
|
+
dot: ".",
|
|
271
|
+
comma: ","
|
|
272
|
+
} }), "?semi=%3B&dot=.&comma=%2C");
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
(0, node_test.describe)("prefix modifier", () => {
|
|
276
|
+
(0, node_test.test)("prefix :n with scalar", () => {
|
|
277
|
+
const t = require_compile.compile("{var:3}");
|
|
278
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ var: "abcdef" }), "abc");
|
|
279
|
+
});
|
|
280
|
+
(0, node_test.test)("prefix with reserved content", () => {
|
|
281
|
+
const t = require_compile.compile("/cut/{x:5}");
|
|
282
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ x: "abc/def?ghi" }), "/cut/abc%2Fd");
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
(0, node_test.describe)("round-trip tests", () => {
|
|
286
|
+
(0, node_test.test)("expand(match(url)) === url (opaque)", () => {
|
|
287
|
+
const t = require_compile.compile("/repos{/owner,repo}{?q,lang}");
|
|
288
|
+
const url = t.expand({
|
|
289
|
+
owner: "alice",
|
|
290
|
+
repo: "hello/world",
|
|
291
|
+
q: "a b",
|
|
292
|
+
lang: "en"
|
|
293
|
+
});
|
|
294
|
+
const m = t.match(url, { encoding: "opaque" });
|
|
295
|
+
(0, node_assert_strict.deepStrictEqual)(m !== null, true);
|
|
296
|
+
const url2 = t.expand(m.vars);
|
|
297
|
+
(0, node_assert_strict.deepStrictEqual)(url2, url);
|
|
298
|
+
});
|
|
299
|
+
(0, node_test.test)("match(expand(vars)) ≅ vars (cooked)", () => {
|
|
300
|
+
const t = require_compile.compile("/u{/id}{?q}");
|
|
301
|
+
const vars = {
|
|
302
|
+
id: "a/b",
|
|
303
|
+
q: "x y"
|
|
304
|
+
};
|
|
305
|
+
const url = t.expand(vars);
|
|
306
|
+
const m = t.match(url, { encoding: "cooked" });
|
|
307
|
+
(0, node_assert_strict.deepStrictEqual)(m !== null, true);
|
|
308
|
+
(0, node_assert_strict.deepStrictEqual)(m.vars, vars);
|
|
309
|
+
});
|
|
310
|
+
(0, node_test.test)("explode list stays list in cooked", () => {
|
|
311
|
+
const t = require_compile.compile("/t{;tags*}");
|
|
312
|
+
const url = t.expand({ tags: ["a b", "c"] });
|
|
313
|
+
const m = t.match(url, { encoding: "cooked" });
|
|
314
|
+
(0, node_assert_strict.deepStrictEqual)(m !== null, true);
|
|
315
|
+
(0, node_assert_strict.deepStrictEqual)(m.vars.tags, ["a b", "c"]);
|
|
316
|
+
});
|
|
317
|
+
(0, node_test.test)("explode map stays map in cooked", () => {
|
|
318
|
+
const t = require_compile.compile("{?m*}");
|
|
319
|
+
const url = t.expand({ m: {
|
|
320
|
+
a: "1 2",
|
|
321
|
+
b: "/"
|
|
322
|
+
} });
|
|
323
|
+
const m = t.match(url, { encoding: "cooked" });
|
|
324
|
+
(0, node_assert_strict.deepStrictEqual)(m !== null, true);
|
|
325
|
+
(0, node_assert_strict.deepStrictEqual)(m.vars.m, {
|
|
326
|
+
a: "1 2",
|
|
327
|
+
b: "/"
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
(0, node_test.describe)("encoding and special cases", () => {
|
|
332
|
+
/**
|
|
333
|
+
* Regression for https://github.com/awwright/uri-template-router/issues/11:
|
|
334
|
+
* Ensure that percent-encoded sequences and '#' handling do not lose information.
|
|
335
|
+
*/
|
|
336
|
+
(0, node_test.test)("opaque preserves raw percent sequences", () => {
|
|
337
|
+
const t = require_compile.compile("{#frag}");
|
|
338
|
+
const url = t.expand({ frag: "%30#" });
|
|
339
|
+
const mOpaque = t.match(url, { encoding: "opaque" });
|
|
340
|
+
(0, node_assert_strict.deepStrictEqual)(mOpaque !== null, true);
|
|
341
|
+
(0, node_assert_strict.deepStrictEqual)(mOpaque.vars.frag, mOpaque.vars.frag);
|
|
342
|
+
const mCooked = t.match(url, { encoding: "cooked" });
|
|
343
|
+
(0, node_assert_strict.deepStrictEqual)(mCooked !== null, true);
|
|
344
|
+
(0, node_assert_strict.deepStrictEqual)(typeof mCooked.vars.frag, "string");
|
|
345
|
+
(0, node_assert_strict.deepStrictEqual)(mCooked.vars.frag.includes("#"), true);
|
|
346
|
+
});
|
|
347
|
+
(0, node_test.test)("bad percent triplet during match => null (strict default)", () => {
|
|
348
|
+
const t = require_compile.compile("/x{/id}");
|
|
349
|
+
const m = t.match("/x/%GZ", { encoding: "opaque" });
|
|
350
|
+
(0, node_assert_strict.deepStrictEqual)(m, null);
|
|
351
|
+
});
|
|
352
|
+
(0, node_test.test)("idempotent expand: do not double-encode existing %XX", () => {
|
|
353
|
+
const t = require_compile.compile("/p{/x}");
|
|
354
|
+
const url = t.expand({ x: "a%2Fb" });
|
|
355
|
+
(0, node_assert_strict.deepStrictEqual)(url, "/p/a%2Fb");
|
|
356
|
+
});
|
|
357
|
+
(0, node_test.test)("space encoding", () => {
|
|
358
|
+
const t = require_compile.compile("/s{/x}{?q}");
|
|
359
|
+
const url = t.expand({
|
|
360
|
+
x: "a b",
|
|
361
|
+
q: "x y"
|
|
362
|
+
});
|
|
363
|
+
(0, node_assert_strict.deepStrictEqual)(url, "/s/a%20b?q=x%20y");
|
|
364
|
+
const m = t.match(url, { encoding: "cooked" });
|
|
365
|
+
(0, node_assert_strict.deepStrictEqual)(m.vars.x, "a b");
|
|
366
|
+
(0, node_assert_strict.deepStrictEqual)(m.vars.q, "x y");
|
|
367
|
+
});
|
|
368
|
+
(0, node_test.test)("greedy capture until next literal", () => {
|
|
369
|
+
const t = require_compile.compile("/r{?q}#end");
|
|
370
|
+
const url = t.expand({ q: "a,b,c" });
|
|
371
|
+
(0, node_assert_strict.deepStrictEqual)(url, "/r?q=a%2Cb%2Cc#end");
|
|
372
|
+
const m = t.match(url, { encoding: "cooked" });
|
|
373
|
+
(0, node_assert_strict.deepStrictEqual)(m !== null, true);
|
|
374
|
+
(0, node_assert_strict.deepStrictEqual)(m.vars.q, "a,b,c");
|
|
375
|
+
});
|
|
376
|
+
(0, node_test.test)("multiple expressions with separators", () => {
|
|
377
|
+
const t = require_compile.compile("/x{/a}{/b}{?c}{&d}");
|
|
378
|
+
const url = t.expand({
|
|
379
|
+
a: "1",
|
|
380
|
+
b: "2/3",
|
|
381
|
+
c: "4 5",
|
|
382
|
+
d: "6"
|
|
383
|
+
});
|
|
384
|
+
(0, node_assert_strict.deepStrictEqual)(url, "/x/1/2%2F3?c=4%205&d=6");
|
|
385
|
+
const m = t.match(url, { encoding: "cooked" });
|
|
386
|
+
(0, node_assert_strict.deepStrictEqual)(m.vars, {
|
|
387
|
+
a: "1",
|
|
388
|
+
b: "2/3",
|
|
389
|
+
c: "4 5",
|
|
390
|
+
d: "6"
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
(0, node_test.describe)("undefined and empty value handling", () => {
|
|
395
|
+
(0, node_test.test)("undefined omits in simple operator", () => {
|
|
396
|
+
const t = require_compile.compile("A{var}Z");
|
|
397
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ var: void 0 }), "AZ");
|
|
398
|
+
});
|
|
399
|
+
(0, node_test.test)("empty string is nameOnly in ';' operator", () => {
|
|
400
|
+
const t = require_compile.compile("{;x}");
|
|
401
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ x: "" }), ";x");
|
|
402
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({ x: void 0 }), "");
|
|
403
|
+
});
|
|
404
|
+
(0, node_test.test)("undefined query param omitted", () => {
|
|
405
|
+
const t = require_compile.compile("/s{?q,lang}");
|
|
406
|
+
(0, node_assert_strict.deepStrictEqual)(t.expand({
|
|
407
|
+
q: void 0,
|
|
408
|
+
lang: "en"
|
|
409
|
+
}), "/s?lang=en");
|
|
410
|
+
});
|
|
411
|
+
(0, node_test.test)("match allows empty value", () => {
|
|
412
|
+
const t = require_compile.compile("/s{?q}");
|
|
413
|
+
const m = t.match("/s?q=", { encoding: "opaque" });
|
|
414
|
+
(0, node_assert_strict.deepStrictEqual)(m !== null, true);
|
|
415
|
+
(0, node_assert_strict.deepStrictEqual)(m.vars.q, "");
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|