@@ -168,12 +168,36 @@ describe('httpbis', () => {
168
168
expect ( httpbis . deriveComponent ( '@path' , new Map ( ) , req ) ) . to . deep . equal ( [
169
169
'/path' ,
170
170
] ) ;
171
+ expect ( httpbis . deriveComponent ( '@path' , new Map ( ) , {
172
+ ...req ,
173
+ url : 'https://www.example.com/path%7D?param=value' ,
174
+ } ) ) . to . deep . equal ( [
175
+ '/path%7D' ,
176
+ ] ) ;
177
+ expect ( httpbis . deriveComponent ( '@path' , new Map ( ) , {
178
+ ...req ,
179
+ url : 'https://www.example.com' ,
180
+ } ) ) . to . deep . equal ( [
181
+ '/' ,
182
+ ] ) ;
171
183
expect ( httpbis . deriveComponent ( '@path' , new Map ( ) , {
172
184
...req ,
173
185
url : new URL ( req . url as string ) ,
174
186
} ) ) . to . deep . equal ( [
175
187
'/path' ,
176
188
] ) ;
189
+ expect ( httpbis . deriveComponent ( '@path' , new Map ( ) , {
190
+ ...req ,
191
+ url : new URL ( 'https://www.example.com/path%7D?param=value' ) ,
192
+ } ) ) . to . deep . equal ( [
193
+ '/path%7D' ,
194
+ ] ) ;
195
+ expect ( httpbis . deriveComponent ( '@path' , new Map ( ) , {
196
+ ...req ,
197
+ url : new URL ( 'https://www.example.com' ) ,
198
+ } ) ) . to . deep . equal ( [
199
+ '/' ,
200
+ ] ) ;
177
201
} ) ;
178
202
it ( 'derives @query' , ( ) => {
179
203
const req : Request = {
@@ -198,6 +222,18 @@ describe('httpbis', () => {
198
222
} ) ) . to . deep . equal ( [
199
223
'?' ,
200
224
] ) ;
225
+ expect ( httpbis . deriveComponent ( '@query' , new Map ( ) , {
226
+ ...req ,
227
+ url : 'https://www.example.com//path?param=value&foo=bar&baz=bat%2Dman' ,
228
+ } ) ) . to . deep . equal ( [
229
+ '?param=value&foo=bar&baz=bat%2Dman' ,
230
+ ] ) ;
231
+ expect ( httpbis . deriveComponent ( '@query' , new Map ( ) , {
232
+ ...req ,
233
+ url : 'https://www.example.com/path' ,
234
+ } ) ) . to . deep . equal ( [
235
+ '?' ,
236
+ ] ) ;
201
237
// with URL objects
202
238
expect ( httpbis . deriveComponent ( '@query' , new Map ( ) , {
203
239
...req ,
@@ -211,6 +247,12 @@ describe('httpbis', () => {
211
247
} ) ) . to . deep . equal ( [
212
248
'?queryString' ,
213
249
] ) ;
250
+ expect ( httpbis . deriveComponent ( '@query' , new Map ( ) , {
251
+ ...req ,
252
+ url : new URL ( 'https://www.example.com//path?param=value&foo=bar&baz=bat%2Dman' ) ,
253
+ } ) ) . to . deep . equal ( [
254
+ '?param=value&foo=bar&baz=bat%2Dman' ,
255
+ ] ) ;
214
256
expect ( httpbis . deriveComponent ( '@query' , new Map ( ) , {
215
257
...req ,
216
258
url : new URL ( 'https://www.example.com/path' ) ,
@@ -242,6 +284,31 @@ describe('httpbis', () => {
242
284
'value' ,
243
285
'value2' ,
244
286
] ) ;
287
+ expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'param' ] ] ) , {
288
+ ...req ,
289
+ url : 'https://example.com/path?param=value%7D¶m=value2%7D' ,
290
+ } ) ) . to . deep . equal ( [
291
+ 'value%7D' ,
292
+ 'value2%7D' ,
293
+ ] ) ;
294
+ expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'var' ] ] ) , {
295
+ ...req ,
296
+ url : 'https://example.com/parameters?var=this%20is%20a%20big%0Amultiline%20value&bar=with+plus+whitespace&fa%C3%A7ade%22%3A%20=something' ,
297
+ } ) ) . to . deep . equal ( [
298
+ 'this%20is%20a%20big%0Amultiline%20value' ,
299
+ ] ) ;
300
+ expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'bar' ] ] ) , {
301
+ ...req ,
302
+ url : 'https://example.com/parameters?var=this%20is%20a%20big%0Amultiline%20value&bar=with+plus+whitespace&fa%C3%A7ade%22%3A%20=something' ,
303
+ } ) ) . to . deep . equal ( [
304
+ 'with%20plus%20whitespace' ,
305
+ ] ) ;
306
+ expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'fa%C3%A7ade%22%3A%20' ] ] ) , {
307
+ ...req ,
308
+ url : 'https://example.com/parameters?var=this%20is%20a%20big%0Amultiline%20value&bar=with+plus+whitespace&fa%C3%A7ade%22%3A%20=something' ,
309
+ } ) ) . to . deep . equal ( [
310
+ 'something' ,
311
+ ] ) ;
245
312
// with URL objects
246
313
expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'baz' ] ] ) , {
247
314
...req ,
@@ -268,6 +335,31 @@ describe('httpbis', () => {
268
335
'value' ,
269
336
'value2' ,
270
337
] ) ;
338
+ expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'param' ] ] ) , {
339
+ ...req ,
340
+ url : new URL ( 'https://example.com/path?param=value%7D¶m=value2%7D' ) ,
341
+ } ) ) . to . deep . equal ( [
342
+ 'value%7D' ,
343
+ 'value2%7D' ,
344
+ ] ) ;
345
+ expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'var' ] ] ) , {
346
+ ...req ,
347
+ url : new URL ( 'https://example.com/parameters?var=this%20is%20a%20big%0Amultiline%20value&bar=with+plus+whitespace&fa%C3%A7ade%22%3A%20=something' ) ,
348
+ } ) ) . to . deep . equal ( [
349
+ 'this%20is%20a%20big%0Amultiline%20value' ,
350
+ ] ) ;
351
+ expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'bar' ] ] ) , {
352
+ ...req ,
353
+ url : new URL ( 'https://example.com/parameters?var=this%20is%20a%20big%0Amultiline%20value&bar=with+plus+whitespace&fa%C3%A7ade%22%3A%20=something' ) ,
354
+ } ) ) . to . deep . equal ( [
355
+ 'with%20plus%20whitespace' ,
356
+ ] ) ;
357
+ expect ( httpbis . deriveComponent ( '@query-param' , new Map ( [ [ 'name' , 'fa%C3%A7ade%22%3A%20' ] ] ) , {
358
+ ...req ,
359
+ url : new URL ( 'https://example.com/parameters?var=this%20is%20a%20big%0Amultiline%20value&bar=with+plus+whitespace&fa%C3%A7ade%22%3A%20=something' ) ,
360
+ } ) ) . to . deep . equal ( [
361
+ 'something' ,
362
+ ] ) ;
271
363
} ) ;
272
364
it ( 'derives @status' , ( ) => {
273
365
const req : Request = {
0 commit comments