path-to-regexp 4.0.5 → 6.2.0

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.
@@ -1,2762 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import * as util from "util";
13
- import * as pathToRegexp from "./index";
14
- /**
15
- * An array of test cases with expected inputs and outputs.
16
- */
17
- var TESTS = [
18
- /**
19
- * Simple paths.
20
- */
21
- [
22
- "/",
23
- undefined,
24
- ["/"],
25
- [
26
- ["/", ["/"], { path: "/", index: 0, params: {} }],
27
- ["/route", null, false]
28
- ],
29
- [
30
- [null, "/"],
31
- [{}, "/"],
32
- [{ id: 123 }, "/"]
33
- ]
34
- ],
35
- [
36
- "/test",
37
- undefined,
38
- ["/test"],
39
- [
40
- ["/test", ["/test"], { path: "/test", index: 0, params: {} }],
41
- ["/route", null, false],
42
- ["/test/route", null, false],
43
- ["/test/", ["/test/"], { path: "/test/", index: 0, params: {} }]
44
- ],
45
- [
46
- [null, "/test"],
47
- [{}, "/test"]
48
- ]
49
- ],
50
- [
51
- "/test/",
52
- undefined,
53
- ["/test/"],
54
- [
55
- ["/test", null],
56
- ["/test/", ["/test/"]],
57
- ["/test//", ["/test//"]]
58
- ],
59
- [[null, "/test/"]]
60
- ],
61
- /**
62
- * Case-sensitive paths.
63
- */
64
- [
65
- "/test",
66
- {
67
- sensitive: true
68
- },
69
- ["/test"],
70
- [
71
- ["/test", ["/test"]],
72
- ["/TEST", null]
73
- ],
74
- [[null, "/test"]]
75
- ],
76
- [
77
- "/TEST",
78
- {
79
- sensitive: true
80
- },
81
- ["/TEST"],
82
- [
83
- ["/test", null],
84
- ["/TEST", ["/TEST"]]
85
- ],
86
- [[null, "/TEST"]]
87
- ],
88
- /**
89
- * Strict mode.
90
- */
91
- [
92
- "/test",
93
- {
94
- strict: true
95
- },
96
- ["/test"],
97
- [
98
- ["/test", ["/test"]],
99
- ["/test/", null],
100
- ["/TEST", ["/TEST"]]
101
- ],
102
- [[null, "/test"]]
103
- ],
104
- [
105
- "/test/",
106
- {
107
- strict: true
108
- },
109
- ["/test/"],
110
- [
111
- ["/test", null],
112
- ["/test/", ["/test/"]],
113
- ["/test//", null]
114
- ],
115
- [[null, "/test/"]]
116
- ],
117
- /**
118
- * Non-ending mode.
119
- */
120
- [
121
- "/test",
122
- {
123
- end: false
124
- },
125
- ["/test"],
126
- [
127
- ["/test", ["/test"]],
128
- ["/test/", ["/test/"]],
129
- ["/test/route", ["/test"]],
130
- ["/route", null]
131
- ],
132
- [[null, "/test"]]
133
- ],
134
- [
135
- "/test/",
136
- {
137
- end: false
138
- },
139
- ["/test/"],
140
- [
141
- ["/test", null],
142
- ["/test/route", ["/test/"]],
143
- ["/test//", ["/test//"]],
144
- ["/test//route", ["/test/"]]
145
- ],
146
- [[null, "/test/"]]
147
- ],
148
- [
149
- "/:test",
150
- {
151
- end: false
152
- },
153
- [
154
- {
155
- name: "test",
156
- prefix: "/",
157
- delimiter: "/",
158
- optional: false,
159
- repeat: false,
160
- pattern: "[^\\/]+?"
161
- }
162
- ],
163
- [
164
- [
165
- "/route",
166
- ["/route", "route"],
167
- { path: "/route", index: 0, params: { test: "route" } }
168
- ],
169
- [
170
- "/caf%C3%A9",
171
- ["/caf%C3%A9", "caf%C3%A9"],
172
- { path: "/caf%C3%A9", index: 0, params: { test: "caf%C3%A9" } }
173
- ],
174
- [
175
- "/caf%C3%A9",
176
- ["/caf%C3%A9", "caf%C3%A9"],
177
- { path: "/caf%C3%A9", index: 0, params: { test: "café" } },
178
- { decode: decodeURIComponent }
179
- ]
180
- ],
181
- [
182
- [{}, null],
183
- [{ test: "abc" }, "/abc"],
184
- [{ test: "a+b" }, "/a+b", { encode: function (value) { return value; } }],
185
- [{ test: "a+b" }, "/test", { encode: function (_, token) { return String(token.name); } }],
186
- [{ test: "a+b" }, "/a%2Bb"]
187
- ]
188
- ],
189
- [
190
- "/:test/",
191
- {
192
- end: false
193
- },
194
- [
195
- {
196
- name: "test",
197
- prefix: "/",
198
- delimiter: "/",
199
- optional: false,
200
- repeat: false,
201
- pattern: "[^\\/]+?"
202
- },
203
- "/"
204
- ],
205
- [
206
- ["/route", null],
207
- ["/route/", ["/route/", "route"]]
208
- ],
209
- [[{ test: "abc" }, "/abc/"]]
210
- ],
211
- [
212
- "",
213
- {
214
- end: false
215
- },
216
- [],
217
- [
218
- ["", [""]],
219
- ["/", ["/"]],
220
- ["route", [""]],
221
- ["/route", [""]],
222
- ["/route/", [""]]
223
- ],
224
- [[null, ""]]
225
- ],
226
- /**
227
- * Non-starting mode.
228
- */
229
- [
230
- "/test",
231
- {
232
- start: false
233
- },
234
- ["/test"],
235
- [
236
- ["/test", ["/test"]],
237
- ["/test/", ["/test/"]],
238
- ["/route/test", ["/test"]],
239
- ["/test/route", null],
240
- ["/route/test/deep", null],
241
- ["/route", null]
242
- ],
243
- [[null, "/test"]]
244
- ],
245
- [
246
- "/test/",
247
- {
248
- start: false
249
- },
250
- ["/test/"],
251
- [
252
- ["/test", null],
253
- ["/test/route", null],
254
- ["/test//route", null],
255
- ["/test//", ["/test//"]],
256
- ["/route/test/", ["/test/"]]
257
- ],
258
- [[null, "/test/"]]
259
- ],
260
- [
261
- "/:test",
262
- {
263
- start: false
264
- },
265
- [
266
- {
267
- name: "test",
268
- prefix: "/",
269
- delimiter: "/",
270
- optional: false,
271
- repeat: false,
272
- pattern: "[^\\/]+?"
273
- }
274
- ],
275
- [["/route", ["/route", "route"]]],
276
- [
277
- [{}, null],
278
- [{ test: "abc" }, "/abc"],
279
- [{ test: "a+b" }, "/a+b", { encode: function (value) { return value; } }],
280
- [{ test: "a+b" }, "/test", { encode: function (_, token) { return String(token.name); } }],
281
- [{ test: "a+b" }, "/a%2Bb"]
282
- ]
283
- ],
284
- [
285
- "/:test/",
286
- {
287
- start: false
288
- },
289
- [
290
- {
291
- name: "test",
292
- prefix: "/",
293
- delimiter: "/",
294
- optional: false,
295
- repeat: false,
296
- pattern: "[^\\/]+?"
297
- },
298
- "/"
299
- ],
300
- [
301
- ["/route", null],
302
- ["/route/", ["/route/", "route"]]
303
- ],
304
- [[{ test: "abc" }, "/abc/"]]
305
- ],
306
- [
307
- "",
308
- {
309
- start: false
310
- },
311
- [],
312
- [
313
- ["", [""]],
314
- ["/", ["/"]],
315
- ["route", [""]],
316
- ["/route", [""]],
317
- ["/route/", ["/"]]
318
- ],
319
- [[null, ""]]
320
- ],
321
- /**
322
- * Combine modes.
323
- */
324
- [
325
- "/test",
326
- {
327
- end: false,
328
- strict: true
329
- },
330
- ["/test"],
331
- [
332
- ["/test", ["/test"]],
333
- ["/test/", ["/test"]],
334
- ["/test/route", ["/test"]]
335
- ],
336
- [[null, "/test"]]
337
- ],
338
- [
339
- "/test/",
340
- {
341
- end: false,
342
- strict: true
343
- },
344
- ["/test/"],
345
- [
346
- ["/test", null],
347
- ["/test/", ["/test/"]],
348
- ["/test//", ["/test/"]],
349
- ["/test/route", ["/test/"]]
350
- ],
351
- [[null, "/test/"]]
352
- ],
353
- [
354
- "/test.json",
355
- {
356
- end: false,
357
- strict: true
358
- },
359
- ["/test.json"],
360
- [
361
- ["/test.json", ["/test.json"]],
362
- ["/test.json.hbs", null],
363
- ["/test.json/route", ["/test.json"]]
364
- ],
365
- [[null, "/test.json"]]
366
- ],
367
- [
368
- "/:test",
369
- {
370
- end: false,
371
- strict: true
372
- },
373
- [
374
- {
375
- name: "test",
376
- prefix: "/",
377
- delimiter: "/",
378
- optional: false,
379
- repeat: false,
380
- pattern: "[^\\/]+?"
381
- }
382
- ],
383
- [
384
- ["/route", ["/route", "route"]],
385
- ["/route/", ["/route", "route"]]
386
- ],
387
- [
388
- [{}, null],
389
- [{ test: "abc" }, "/abc"]
390
- ]
391
- ],
392
- [
393
- "/:test/",
394
- {
395
- end: false,
396
- strict: true
397
- },
398
- [
399
- {
400
- name: "test",
401
- prefix: "/",
402
- delimiter: "/",
403
- optional: false,
404
- repeat: false,
405
- pattern: "[^\\/]+?"
406
- },
407
- "/"
408
- ],
409
- [
410
- ["/route", null],
411
- ["/route/", ["/route/", "route"]]
412
- ],
413
- [[{ test: "foobar" }, "/foobar/"]]
414
- ],
415
- [
416
- "/test",
417
- {
418
- start: false,
419
- end: false
420
- },
421
- ["/test"],
422
- [
423
- ["/test", ["/test"]],
424
- ["/test/", ["/test/"]],
425
- ["/test/route", ["/test"]],
426
- ["/route/test/deep", ["/test"]]
427
- ],
428
- [[null, "/test"]]
429
- ],
430
- [
431
- "/test/",
432
- {
433
- start: false,
434
- end: false
435
- },
436
- ["/test/"],
437
- [
438
- ["/test", null],
439
- ["/test/", ["/test/"]],
440
- ["/test//", ["/test//"]],
441
- ["/test/route", ["/test/"]],
442
- ["/route/test/deep", ["/test/"]]
443
- ],
444
- [[null, "/test/"]]
445
- ],
446
- [
447
- "/test.json",
448
- {
449
- start: false,
450
- end: false
451
- },
452
- ["/test.json"],
453
- [
454
- ["/test.json", ["/test.json"]],
455
- ["/test.json.hbs", null],
456
- ["/test.json/route", ["/test.json"]],
457
- ["/route/test.json/deep", ["/test.json"]]
458
- ],
459
- [[null, "/test.json"]]
460
- ],
461
- [
462
- "/:test",
463
- {
464
- start: false,
465
- end: false
466
- },
467
- [
468
- {
469
- name: "test",
470
- prefix: "/",
471
- delimiter: "/",
472
- optional: false,
473
- repeat: false,
474
- pattern: "[^\\/]+?"
475
- }
476
- ],
477
- [
478
- ["/route", ["/route", "route"]],
479
- ["/route/", ["/route/", "route"]]
480
- ],
481
- [
482
- [{}, null],
483
- [{ test: "abc" }, "/abc"]
484
- ]
485
- ],
486
- [
487
- "/:test/",
488
- {
489
- end: false,
490
- strict: true
491
- },
492
- [
493
- {
494
- name: "test",
495
- prefix: "/",
496
- delimiter: "/",
497
- optional: false,
498
- repeat: false,
499
- pattern: "[^\\/]+?"
500
- },
501
- "/"
502
- ],
503
- [
504
- ["/route", null],
505
- ["/route/", ["/route/", "route"]]
506
- ],
507
- [[{ test: "foobar" }, "/foobar/"]]
508
- ],
509
- /**
510
- * Arrays of simple paths.
511
- */
512
- [
513
- ["/one", "/two"],
514
- undefined,
515
- [],
516
- [
517
- ["/one", ["/one"]],
518
- ["/two", ["/two"]],
519
- ["/three", null],
520
- ["/one/two", null]
521
- ],
522
- []
523
- ],
524
- /**
525
- * Non-ending simple path.
526
- */
527
- [
528
- "/test",
529
- {
530
- end: false
531
- },
532
- ["/test"],
533
- [["/test/route", ["/test"]]],
534
- [[null, "/test"]]
535
- ],
536
- /**
537
- * Single named parameter.
538
- */
539
- [
540
- "/:test",
541
- undefined,
542
- [
543
- {
544
- name: "test",
545
- prefix: "/",
546
- delimiter: "/",
547
- optional: false,
548
- repeat: false,
549
- pattern: "[^\\/]+?"
550
- }
551
- ],
552
- [
553
- ["/route", ["/route", "route"]],
554
- ["/another", ["/another", "another"]],
555
- ["/something/else", null],
556
- ["/route.json", ["/route.json", "route.json"]],
557
- ["/something%2Felse", ["/something%2Felse", "something%2Felse"]],
558
- [
559
- "/something%2Felse%2Fmore",
560
- ["/something%2Felse%2Fmore", "something%2Felse%2Fmore"]
561
- ],
562
- ["/;,:@&=+$-_.!~*()", ["/;,:@&=+$-_.!~*()", ";,:@&=+$-_.!~*()"]]
563
- ],
564
- [
565
- [{ test: "route" }, "/route"],
566
- [{ test: "something/else" }, "/something%2Felse"],
567
- [{ test: "something/else/more" }, "/something%2Felse%2Fmore"]
568
- ]
569
- ],
570
- [
571
- "/:test",
572
- {
573
- strict: true
574
- },
575
- [
576
- {
577
- name: "test",
578
- prefix: "/",
579
- delimiter: "/",
580
- optional: false,
581
- repeat: false,
582
- pattern: "[^\\/]+?"
583
- }
584
- ],
585
- [
586
- ["/route", ["/route", "route"]],
587
- ["/route/", null]
588
- ],
589
- [[{ test: "route" }, "/route"]]
590
- ],
591
- [
592
- "/:test/",
593
- {
594
- strict: true
595
- },
596
- [
597
- {
598
- name: "test",
599
- prefix: "/",
600
- delimiter: "/",
601
- optional: false,
602
- repeat: false,
603
- pattern: "[^\\/]+?"
604
- },
605
- "/"
606
- ],
607
- [
608
- ["/route/", ["/route/", "route"]],
609
- ["/route//", null]
610
- ],
611
- [[{ test: "route" }, "/route/"]]
612
- ],
613
- [
614
- "/:test",
615
- {
616
- end: false
617
- },
618
- [
619
- {
620
- name: "test",
621
- prefix: "/",
622
- delimiter: "/",
623
- optional: false,
624
- repeat: false,
625
- pattern: "[^\\/]+?"
626
- }
627
- ],
628
- [
629
- ["/route.json", ["/route.json", "route.json"]],
630
- ["/route//", ["/route", "route"]]
631
- ],
632
- [[{ test: "route" }, "/route"]]
633
- ],
634
- /**
635
- * Optional named parameter.
636
- */
637
- [
638
- "/:test?",
639
- undefined,
640
- [
641
- {
642
- name: "test",
643
- prefix: "/",
644
- delimiter: "/",
645
- optional: true,
646
- repeat: false,
647
- pattern: "[^\\/]+?"
648
- }
649
- ],
650
- [
651
- [
652
- "/route",
653
- ["/route", "route"],
654
- { path: "/route", index: 0, params: { test: "route" } }
655
- ],
656
- ["/route/nested", null, false],
657
- ["/", ["/", undefined], { path: "/", index: 0, params: {} }],
658
- ["//", null]
659
- ],
660
- [
661
- [null, ""],
662
- [{ test: "foobar" }, "/foobar"]
663
- ]
664
- ],
665
- [
666
- "/:test?",
667
- {
668
- strict: true
669
- },
670
- [
671
- {
672
- name: "test",
673
- prefix: "/",
674
- delimiter: "/",
675
- optional: true,
676
- repeat: false,
677
- pattern: "[^\\/]+?"
678
- }
679
- ],
680
- [
681
- ["/route", ["/route", "route"]],
682
- ["/", null],
683
- ["//", null]
684
- ],
685
- [
686
- [null, ""],
687
- [{ test: "foobar" }, "/foobar"]
688
- ]
689
- ],
690
- [
691
- "/:test?/",
692
- {
693
- strict: true
694
- },
695
- [
696
- {
697
- name: "test",
698
- prefix: "/",
699
- delimiter: "/",
700
- optional: true,
701
- repeat: false,
702
- pattern: "[^\\/]+?"
703
- },
704
- "/"
705
- ],
706
- [
707
- ["/route", null],
708
- ["/route/", ["/route/", "route"]],
709
- ["/", ["/", undefined]],
710
- ["//", null]
711
- ],
712
- [
713
- [null, "/"],
714
- [{ test: "foobar" }, "/foobar/"]
715
- ]
716
- ],
717
- [
718
- "/:test?/bar",
719
- undefined,
720
- [
721
- {
722
- name: "test",
723
- prefix: "/",
724
- delimiter: "/",
725
- optional: true,
726
- repeat: false,
727
- pattern: "[^\\/]+?"
728
- },
729
- "/bar"
730
- ],
731
- [
732
- ["/bar", ["/bar", undefined]],
733
- ["/foo/bar", ["/foo/bar", "foo"]]
734
- ],
735
- [
736
- [null, "/bar"],
737
- [{ test: "foo" }, "/foo/bar"]
738
- ]
739
- ],
740
- [
741
- "/:test?-bar",
742
- undefined,
743
- [
744
- {
745
- name: "test",
746
- prefix: "/",
747
- delimiter: "/",
748
- optional: true,
749
- repeat: false,
750
- pattern: "[^\\/]+?"
751
- },
752
- "-bar"
753
- ],
754
- [
755
- ["-bar", ["-bar", undefined]],
756
- ["/-bar", null],
757
- ["/foo-bar", ["/foo-bar", "foo"]]
758
- ],
759
- [
760
- [undefined, "-bar"],
761
- [{ test: "foo" }, "/foo-bar"]
762
- ]
763
- ],
764
- [
765
- "/:test*-bar",
766
- undefined,
767
- [
768
- {
769
- name: "test",
770
- prefix: "/",
771
- delimiter: "/",
772
- optional: true,
773
- repeat: true,
774
- pattern: "[^\\/]+?"
775
- },
776
- "-bar"
777
- ],
778
- [
779
- ["-bar", ["-bar", undefined]],
780
- ["/-bar", null],
781
- ["/foo-bar", ["/foo-bar", "foo"]],
782
- ["/foo/baz-bar", ["/foo/baz-bar", "foo/baz"]]
783
- ],
784
- [[{ test: "foo" }, "/foo-bar"]]
785
- ],
786
- /**
787
- * Repeated one or more times parameters.
788
- */
789
- [
790
- "/:test+",
791
- undefined,
792
- [
793
- {
794
- name: "test",
795
- prefix: "/",
796
- delimiter: "/",
797
- optional: false,
798
- repeat: true,
799
- pattern: "[^\\/]+?"
800
- }
801
- ],
802
- [
803
- ["/", null, false],
804
- [
805
- "/route",
806
- ["/route", "route"],
807
- { path: "/route", index: 0, params: { test: ["route"] } }
808
- ],
809
- [
810
- "/some/basic/route",
811
- ["/some/basic/route", "some/basic/route"],
812
- {
813
- path: "/some/basic/route",
814
- index: 0,
815
- params: { test: ["some", "basic", "route"] }
816
- }
817
- ],
818
- ["//", null, false]
819
- ],
820
- [
821
- [{}, null],
822
- [{ test: "foobar" }, "/foobar"],
823
- [{ test: ["a", "b", "c"] }, "/a/b/c"]
824
- ]
825
- ],
826
- [
827
- "/:test(\\d+)+",
828
- undefined,
829
- [
830
- {
831
- name: "test",
832
- prefix: "/",
833
- delimiter: "/",
834
- optional: false,
835
- repeat: true,
836
- pattern: "\\d+"
837
- }
838
- ],
839
- [
840
- ["/abc/456/789", null],
841
- ["/123/456/789", ["/123/456/789", "123/456/789"]]
842
- ],
843
- [
844
- [{ test: "abc" }, null],
845
- [{ test: 123 }, "/123"],
846
- [{ test: [1, 2, 3] }, "/1/2/3"]
847
- ]
848
- ],
849
- [
850
- "/route.:ext(json|xml)+",
851
- undefined,
852
- [
853
- "/route",
854
- {
855
- name: "ext",
856
- prefix: ".",
857
- delimiter: ".",
858
- optional: false,
859
- repeat: true,
860
- pattern: "json|xml"
861
- }
862
- ],
863
- [
864
- ["/route", null],
865
- ["/route.json", ["/route.json", "json"]],
866
- ["/route.xml.json", ["/route.xml.json", "xml.json"]],
867
- ["/route.html", null]
868
- ],
869
- [
870
- [{ ext: "foobar" }, null],
871
- [{ ext: "xml" }, "/route.xml"],
872
- [{ ext: ["xml", "json"] }, "/route.xml.json"]
873
- ]
874
- ],
875
- [
876
- "/route.:ext/test",
877
- undefined,
878
- [
879
- "/route",
880
- {
881
- name: "ext",
882
- prefix: ".",
883
- delimiter: ".",
884
- optional: false,
885
- repeat: false,
886
- pattern: "[^\\.\\/]+?"
887
- },
888
- "/test"
889
- ],
890
- [
891
- ["/route", null],
892
- ["/route.json", null],
893
- ["/route.xml/test", ["/route.xml/test", "xml"]],
894
- ["/route.json.gz/test", null]
895
- ],
896
- [[{ ext: "xml" }, "/route.xml/test"]]
897
- ],
898
- /**
899
- * Repeated zero or more times parameters.
900
- */
901
- [
902
- "/:test*",
903
- undefined,
904
- [
905
- {
906
- name: "test",
907
- prefix: "/",
908
- delimiter: "/",
909
- optional: true,
910
- repeat: true,
911
- pattern: "[^\\/]+?"
912
- }
913
- ],
914
- [
915
- ["/", ["/", undefined], { path: "/", index: 0, params: {} }],
916
- ["//", null, false],
917
- [
918
- "/route",
919
- ["/route", "route"],
920
- { path: "/route", index: 0, params: { test: ["route"] } }
921
- ],
922
- [
923
- "/some/basic/route",
924
- ["/some/basic/route", "some/basic/route"],
925
- {
926
- path: "/some/basic/route",
927
- index: 0,
928
- params: { test: ["some", "basic", "route"] }
929
- }
930
- ]
931
- ],
932
- [
933
- [{}, ""],
934
- [{ test: [] }, ""],
935
- [{ test: "foobar" }, "/foobar"],
936
- [{ test: ["foo", "bar"] }, "/foo/bar"]
937
- ]
938
- ],
939
- [
940
- "/route.:ext([a-z]+)*",
941
- undefined,
942
- [
943
- "/route",
944
- {
945
- name: "ext",
946
- prefix: ".",
947
- delimiter: ".",
948
- optional: true,
949
- repeat: true,
950
- pattern: "[a-z]+"
951
- }
952
- ],
953
- [
954
- ["/route", ["/route", undefined]],
955
- ["/route.json", ["/route.json", "json"]],
956
- ["/route.json.xml", ["/route.json.xml", "json.xml"]],
957
- ["/route.123", null]
958
- ],
959
- [
960
- [{}, "/route"],
961
- [{ ext: [] }, "/route"],
962
- [{ ext: "123" }, null],
963
- [{ ext: "foobar" }, "/route.foobar"],
964
- [{ ext: ["foo", "bar"] }, "/route.foo.bar"]
965
- ]
966
- ],
967
- /**
968
- * Custom named parameters.
969
- */
970
- [
971
- "/:test(\\d+)",
972
- undefined,
973
- [
974
- {
975
- name: "test",
976
- prefix: "/",
977
- delimiter: "/",
978
- optional: false,
979
- repeat: false,
980
- pattern: "\\d+"
981
- }
982
- ],
983
- [
984
- ["/123", ["/123", "123"]],
985
- ["/abc", null],
986
- ["/123/abc", null]
987
- ],
988
- [
989
- [{ test: "abc" }, null],
990
- [{ test: "abc" }, "/abc", { validate: false }],
991
- [{ test: "123" }, "/123"]
992
- ]
993
- ],
994
- [
995
- "/:test(\\d+)",
996
- {
997
- end: false
998
- },
999
- [
1000
- {
1001
- name: "test",
1002
- prefix: "/",
1003
- delimiter: "/",
1004
- optional: false,
1005
- repeat: false,
1006
- pattern: "\\d+"
1007
- }
1008
- ],
1009
- [
1010
- ["/123", ["/123", "123"]],
1011
- ["/abc", null],
1012
- ["/123/abc", ["/123", "123"]]
1013
- ],
1014
- [[{ test: "123" }, "/123"]]
1015
- ],
1016
- [
1017
- "/:test(.*)",
1018
- undefined,
1019
- [
1020
- {
1021
- name: "test",
1022
- prefix: "/",
1023
- delimiter: "/",
1024
- optional: false,
1025
- repeat: false,
1026
- pattern: ".*"
1027
- }
1028
- ],
1029
- [
1030
- ["/anything/goes/here", ["/anything/goes/here", "anything/goes/here"]],
1031
- ["/;,:@&=/+$-_.!/~*()", ["/;,:@&=/+$-_.!/~*()", ";,:@&=/+$-_.!/~*()"]]
1032
- ],
1033
- [
1034
- [{ test: "" }, "/"],
1035
- [{ test: "abc" }, "/abc"],
1036
- [{ test: "abc/123" }, "/abc%2F123"],
1037
- [{ test: "abc/123/456" }, "/abc%2F123%2F456"]
1038
- ]
1039
- ],
1040
- [
1041
- "/:route([a-z]+)",
1042
- undefined,
1043
- [
1044
- {
1045
- name: "route",
1046
- prefix: "/",
1047
- delimiter: "/",
1048
- optional: false,
1049
- repeat: false,
1050
- pattern: "[a-z]+"
1051
- }
1052
- ],
1053
- [
1054
- ["/abcde", ["/abcde", "abcde"]],
1055
- ["/12345", null]
1056
- ],
1057
- [
1058
- [{ route: "" }, null],
1059
- [{ route: "" }, "/", { validate: false }],
1060
- [{ route: "123" }, null],
1061
- [{ route: "123" }, "/123", { validate: false }],
1062
- [{ route: "abc" }, "/abc"]
1063
- ]
1064
- ],
1065
- [
1066
- "/:route(this|that)",
1067
- undefined,
1068
- [
1069
- {
1070
- name: "route",
1071
- prefix: "/",
1072
- delimiter: "/",
1073
- optional: false,
1074
- repeat: false,
1075
- pattern: "this|that"
1076
- }
1077
- ],
1078
- [
1079
- ["/this", ["/this", "this"]],
1080
- ["/that", ["/that", "that"]],
1081
- ["/foo", null]
1082
- ],
1083
- [
1084
- [{ route: "this" }, "/this"],
1085
- [{ route: "foo" }, null],
1086
- [{ route: "foo" }, "/foo", { validate: false }],
1087
- [{ route: "that" }, "/that"]
1088
- ]
1089
- ],
1090
- [
1091
- "/:path(abc|xyz)*",
1092
- undefined,
1093
- [
1094
- {
1095
- name: "path",
1096
- prefix: "/",
1097
- delimiter: "/",
1098
- optional: true,
1099
- repeat: true,
1100
- pattern: "abc|xyz"
1101
- }
1102
- ],
1103
- [
1104
- ["/abc", ["/abc", "abc"]],
1105
- ["/abc/abc", ["/abc/abc", "abc/abc"]],
1106
- ["/xyz/xyz", ["/xyz/xyz", "xyz/xyz"]],
1107
- ["/abc/xyz", ["/abc/xyz", "abc/xyz"]],
1108
- ["/abc/xyz/abc/xyz", ["/abc/xyz/abc/xyz", "abc/xyz/abc/xyz"]],
1109
- ["/xyzxyz", null]
1110
- ],
1111
- [
1112
- [{ path: "abc" }, "/abc"],
1113
- [{ path: ["abc", "xyz"] }, "/abc/xyz"],
1114
- [{ path: ["xyz", "abc", "xyz"] }, "/xyz/abc/xyz"],
1115
- [{ path: "abc123" }, null],
1116
- [{ path: "abc123" }, "/abc123", { validate: false }],
1117
- [{ path: "abcxyz" }, null],
1118
- [{ path: "abcxyz" }, "/abcxyz", { validate: false }]
1119
- ]
1120
- ],
1121
- /**
1122
- * Prefixed slashes could be omitted.
1123
- */
1124
- [
1125
- "test",
1126
- undefined,
1127
- ["test"],
1128
- [
1129
- ["test", ["test"]],
1130
- ["/test", null]
1131
- ],
1132
- [[null, "test"]]
1133
- ],
1134
- [
1135
- ":test",
1136
- undefined,
1137
- [
1138
- {
1139
- name: "test",
1140
- prefix: "",
1141
- delimiter: "/",
1142
- optional: false,
1143
- repeat: false,
1144
- pattern: "[^\\/]+?"
1145
- }
1146
- ],
1147
- [
1148
- ["route", ["route", "route"]],
1149
- ["/route", null],
1150
- ["route/", ["route/", "route"]]
1151
- ],
1152
- [
1153
- [{ test: "" }, null],
1154
- [{}, null],
1155
- [{ test: null }, null],
1156
- [{ test: "route" }, "route"]
1157
- ]
1158
- ],
1159
- [
1160
- ":test",
1161
- {
1162
- strict: true
1163
- },
1164
- [
1165
- {
1166
- name: "test",
1167
- prefix: "",
1168
- delimiter: "/",
1169
- optional: false,
1170
- repeat: false,
1171
- pattern: "[^\\/]+?"
1172
- }
1173
- ],
1174
- [
1175
- ["route", ["route", "route"]],
1176
- ["/route", null],
1177
- ["route/", null]
1178
- ],
1179
- [[{ test: "route" }, "route"]]
1180
- ],
1181
- [
1182
- ":test",
1183
- {
1184
- end: false
1185
- },
1186
- [
1187
- {
1188
- name: "test",
1189
- prefix: "",
1190
- delimiter: "/",
1191
- optional: false,
1192
- repeat: false,
1193
- pattern: "[^\\/]+?"
1194
- }
1195
- ],
1196
- [
1197
- ["route", ["route", "route"]],
1198
- ["/route", null],
1199
- ["route/", ["route/", "route"]],
1200
- ["route/foobar", ["route", "route"]]
1201
- ],
1202
- [[{ test: "route" }, "route"]]
1203
- ],
1204
- [
1205
- ":test?",
1206
- undefined,
1207
- [
1208
- {
1209
- name: "test",
1210
- prefix: "",
1211
- delimiter: "/",
1212
- optional: true,
1213
- repeat: false,
1214
- pattern: "[^\\/]+?"
1215
- }
1216
- ],
1217
- [
1218
- ["route", ["route", "route"]],
1219
- ["/route", null],
1220
- ["", ["", undefined]],
1221
- ["route/foobar", null]
1222
- ],
1223
- [
1224
- [{}, ""],
1225
- [{ test: "" }, null],
1226
- [{ test: "route" }, "route"]
1227
- ]
1228
- ],
1229
- [
1230
- ":test+",
1231
- undefined,
1232
- [
1233
- {
1234
- name: "test",
1235
- prefix: "",
1236
- delimiter: "/",
1237
- optional: false,
1238
- repeat: true,
1239
- pattern: "[^\\/]+?"
1240
- }
1241
- ],
1242
- [
1243
- ["route", ["route", "route"]],
1244
- ["/route", null],
1245
- ["", null],
1246
- ["foo/bar", ["foo/bar", "foo/bar"]]
1247
- ],
1248
- [
1249
- [{}, null],
1250
- [{ test: "" }, null],
1251
- [{ test: ["route"] }, "route"],
1252
- [{ test: ["foo", "bar"] }, "foo/bar"]
1253
- ]
1254
- ],
1255
- /**
1256
- * Formats.
1257
- */
1258
- [
1259
- "/test.json",
1260
- undefined,
1261
- ["/test.json"],
1262
- [
1263
- ["/test.json", ["/test.json"]],
1264
- ["/route.json", null]
1265
- ],
1266
- [[{}, "/test.json"]]
1267
- ],
1268
- [
1269
- "/:test.json",
1270
- undefined,
1271
- [
1272
- {
1273
- name: "test",
1274
- prefix: "/",
1275
- delimiter: "/",
1276
- optional: false,
1277
- repeat: false,
1278
- pattern: "[^\\/]+?"
1279
- },
1280
- ".json"
1281
- ],
1282
- [
1283
- ["/.json", null],
1284
- ["/test.json", ["/test.json", "test"]],
1285
- ["/route.json", ["/route.json", "route"]],
1286
- ["/route.json.json", ["/route.json.json", "route.json"]]
1287
- ],
1288
- [
1289
- [{ test: "" }, null],
1290
- [{ test: "foo" }, "/foo.json"]
1291
- ]
1292
- ],
1293
- /**
1294
- * Format params.
1295
- */
1296
- [
1297
- "/test.:format",
1298
- undefined,
1299
- [
1300
- "/test",
1301
- {
1302
- name: "format",
1303
- prefix: ".",
1304
- delimiter: ".",
1305
- optional: false,
1306
- repeat: false,
1307
- pattern: "[^\\.\\/]+?"
1308
- }
1309
- ],
1310
- [
1311
- ["/test.html", ["/test.html", "html"]],
1312
- ["/test.hbs.html", null]
1313
- ],
1314
- [
1315
- [{}, null],
1316
- [{ format: "" }, null],
1317
- [{ format: "foo" }, "/test.foo"]
1318
- ]
1319
- ],
1320
- [
1321
- "/test.:format.:format",
1322
- undefined,
1323
- [
1324
- "/test",
1325
- {
1326
- name: "format",
1327
- prefix: ".",
1328
- delimiter: ".",
1329
- optional: false,
1330
- repeat: false,
1331
- pattern: "[^\\.\\/]+?"
1332
- },
1333
- {
1334
- name: "format",
1335
- prefix: ".",
1336
- delimiter: ".",
1337
- optional: false,
1338
- repeat: false,
1339
- pattern: "[^\\.\\/]+?"
1340
- }
1341
- ],
1342
- [
1343
- ["/test.html", null],
1344
- ["/test.hbs.html", ["/test.hbs.html", "hbs", "html"]]
1345
- ],
1346
- [
1347
- [{ format: "foo.bar" }, null],
1348
- [{ format: "foo" }, "/test.foo.foo"]
1349
- ]
1350
- ],
1351
- [
1352
- "/test.:format+",
1353
- undefined,
1354
- [
1355
- "/test",
1356
- {
1357
- name: "format",
1358
- prefix: ".",
1359
- delimiter: ".",
1360
- optional: false,
1361
- repeat: true,
1362
- pattern: "[^\\.\\/]+?"
1363
- }
1364
- ],
1365
- [
1366
- ["/test.html", ["/test.html", "html"]],
1367
- ["/test.hbs.html", ["/test.hbs.html", "hbs.html"]]
1368
- ],
1369
- [
1370
- [{ format: [] }, null],
1371
- [{ format: "foo" }, "/test.foo"],
1372
- [{ format: ["foo", "bar"] }, "/test.foo.bar"]
1373
- ]
1374
- ],
1375
- [
1376
- "/test.:format",
1377
- {
1378
- end: false
1379
- },
1380
- [
1381
- "/test",
1382
- {
1383
- name: "format",
1384
- prefix: ".",
1385
- delimiter: ".",
1386
- optional: false,
1387
- repeat: false,
1388
- pattern: "[^\\.\\/]+?"
1389
- }
1390
- ],
1391
- [
1392
- ["/test.html", ["/test.html", "html"]],
1393
- ["/test.hbs.html", null]
1394
- ],
1395
- [[{ format: "foo" }, "/test.foo"]]
1396
- ],
1397
- [
1398
- "/test.:format.",
1399
- undefined,
1400
- [
1401
- "/test",
1402
- {
1403
- name: "format",
1404
- prefix: ".",
1405
- delimiter: ".",
1406
- optional: false,
1407
- repeat: false,
1408
- pattern: "[^\\.\\/]+?"
1409
- },
1410
- "."
1411
- ],
1412
- [
1413
- ["/test.html.", ["/test.html.", "html"]],
1414
- ["/test.hbs.html", null]
1415
- ],
1416
- [
1417
- [{ format: "" }, null],
1418
- [{ format: "foo" }, "/test.foo."]
1419
- ]
1420
- ],
1421
- /**
1422
- * Format and path params.
1423
- */
1424
- [
1425
- "/:test.:format",
1426
- undefined,
1427
- [
1428
- {
1429
- name: "test",
1430
- prefix: "/",
1431
- delimiter: "/",
1432
- optional: false,
1433
- repeat: false,
1434
- pattern: "[^\\/]+?"
1435
- },
1436
- {
1437
- name: "format",
1438
- prefix: ".",
1439
- delimiter: ".",
1440
- optional: false,
1441
- repeat: false,
1442
- pattern: "[^\\.\\/]+?"
1443
- }
1444
- ],
1445
- [
1446
- ["/route.html", ["/route.html", "route", "html"]],
1447
- ["/route", null],
1448
- ["/route.html.json", ["/route.html.json", "route.html", "json"]]
1449
- ],
1450
- [
1451
- [{}, null],
1452
- [{ test: "route", format: "foo" }, "/route.foo"]
1453
- ]
1454
- ],
1455
- [
1456
- "/:test.:format?",
1457
- undefined,
1458
- [
1459
- {
1460
- name: "test",
1461
- prefix: "/",
1462
- delimiter: "/",
1463
- optional: false,
1464
- repeat: false,
1465
- pattern: "[^\\/]+?"
1466
- },
1467
- {
1468
- name: "format",
1469
- prefix: ".",
1470
- delimiter: ".",
1471
- optional: true,
1472
- repeat: false,
1473
- pattern: "[^\\.\\/]+?"
1474
- }
1475
- ],
1476
- [
1477
- ["/route", ["/route", "route", undefined]],
1478
- ["/route.json", ["/route.json", "route", "json"]],
1479
- ["/route.json.html", ["/route.json.html", "route.json", "html"]]
1480
- ],
1481
- [
1482
- [{ test: "route" }, "/route"],
1483
- [{ test: "route", format: "" }, null],
1484
- [{ test: "route", format: "foo" }, "/route.foo"]
1485
- ]
1486
- ],
1487
- [
1488
- "/:test.:format?",
1489
- {
1490
- end: false
1491
- },
1492
- [
1493
- {
1494
- name: "test",
1495
- prefix: "/",
1496
- delimiter: "/",
1497
- optional: false,
1498
- repeat: false,
1499
- pattern: "[^\\/]+?"
1500
- },
1501
- {
1502
- name: "format",
1503
- prefix: ".",
1504
- delimiter: ".",
1505
- optional: true,
1506
- repeat: false,
1507
- pattern: "[^\\.\\/]+?"
1508
- }
1509
- ],
1510
- [
1511
- ["/route", ["/route", "route", undefined]],
1512
- ["/route.json", ["/route.json", "route", "json"]],
1513
- ["/route.json.html", ["/route.json.html", "route.json", "html"]]
1514
- ],
1515
- [
1516
- [{ test: "route" }, "/route"],
1517
- [{ test: "route", format: undefined }, "/route"],
1518
- [{ test: "route", format: "" }, null],
1519
- [{ test: "route", format: "foo" }, "/route.foo"]
1520
- ]
1521
- ],
1522
- [
1523
- "/test.:format(.*)z",
1524
- {
1525
- end: false
1526
- },
1527
- [
1528
- "/test",
1529
- {
1530
- name: "format",
1531
- prefix: ".",
1532
- delimiter: ".",
1533
- optional: false,
1534
- repeat: false,
1535
- pattern: ".*"
1536
- },
1537
- "z"
1538
- ],
1539
- [
1540
- ["/test.abc", null],
1541
- ["/test.z", ["/test.z", ""]],
1542
- ["/test.abcz", ["/test.abcz", "abc"]]
1543
- ],
1544
- [
1545
- [{}, null],
1546
- [{ format: "" }, "/test.z"],
1547
- [{ format: "foo" }, "/test.fooz"]
1548
- ]
1549
- ],
1550
- /**
1551
- * Unnamed params.
1552
- */
1553
- [
1554
- "/(\\d+)",
1555
- undefined,
1556
- [
1557
- {
1558
- name: 0,
1559
- prefix: "/",
1560
- delimiter: "/",
1561
- optional: false,
1562
- repeat: false,
1563
- pattern: "\\d+"
1564
- }
1565
- ],
1566
- [
1567
- ["/123", ["/123", "123"]],
1568
- ["/abc", null],
1569
- ["/123/abc", null]
1570
- ],
1571
- [
1572
- [{}, null],
1573
- [{ "0": "123" }, "/123"]
1574
- ]
1575
- ],
1576
- [
1577
- "/(\\d+)",
1578
- {
1579
- end: false
1580
- },
1581
- [
1582
- {
1583
- name: 0,
1584
- prefix: "/",
1585
- delimiter: "/",
1586
- optional: false,
1587
- repeat: false,
1588
- pattern: "\\d+"
1589
- }
1590
- ],
1591
- [
1592
- ["/123", ["/123", "123"]],
1593
- ["/abc", null],
1594
- ["/123/abc", ["/123", "123"]],
1595
- ["/123/", ["/123/", "123"]]
1596
- ],
1597
- [[{ "0": "123" }, "/123"]]
1598
- ],
1599
- [
1600
- "/(\\d+)?",
1601
- undefined,
1602
- [
1603
- {
1604
- name: 0,
1605
- prefix: "/",
1606
- delimiter: "/",
1607
- optional: true,
1608
- repeat: false,
1609
- pattern: "\\d+"
1610
- }
1611
- ],
1612
- [
1613
- ["/", ["/", undefined]],
1614
- ["/123", ["/123", "123"]]
1615
- ],
1616
- [
1617
- [{}, ""],
1618
- [{ "0": "123" }, "/123"]
1619
- ]
1620
- ],
1621
- [
1622
- "/(.*)",
1623
- undefined,
1624
- [
1625
- {
1626
- name: 0,
1627
- prefix: "/",
1628
- delimiter: "/",
1629
- optional: false,
1630
- repeat: false,
1631
- pattern: ".*"
1632
- }
1633
- ],
1634
- [
1635
- ["/", ["/", ""]],
1636
- ["/route", ["/route", "route"]],
1637
- ["/route/nested", ["/route/nested", "route/nested"]]
1638
- ],
1639
- [
1640
- [{ "0": "" }, "/"],
1641
- [{ "0": "123" }, "/123"]
1642
- ]
1643
- ],
1644
- [
1645
- "/route\\(\\\\(\\d+\\\\)\\)",
1646
- undefined,
1647
- [
1648
- "/route(\\",
1649
- {
1650
- name: 0,
1651
- prefix: "",
1652
- delimiter: "/",
1653
- optional: false,
1654
- repeat: false,
1655
- pattern: "\\d+\\\\"
1656
- },
1657
- ")"
1658
- ],
1659
- [["/route(\\123\\)", ["/route(\\123\\)", "123\\"]]],
1660
- []
1661
- ],
1662
- [
1663
- "/(login)?",
1664
- undefined,
1665
- [
1666
- {
1667
- name: 0,
1668
- prefix: "/",
1669
- delimiter: "/",
1670
- optional: true,
1671
- repeat: false,
1672
- pattern: "login"
1673
- }
1674
- ],
1675
- [
1676
- ["/", ["/", undefined]],
1677
- ["/login", ["/login", "login"]]
1678
- ],
1679
- []
1680
- ],
1681
- /**
1682
- * Regexps.
1683
- */
1684
- [/.*/, undefined, [], [["/match/anything", ["/match/anything"]]], []],
1685
- [
1686
- /(.*)/,
1687
- undefined,
1688
- [
1689
- {
1690
- name: 0,
1691
- prefix: "",
1692
- delimiter: "",
1693
- optional: false,
1694
- repeat: false,
1695
- pattern: ""
1696
- }
1697
- ],
1698
- [["/match/anything", ["/match/anything", "/match/anything"]]],
1699
- []
1700
- ],
1701
- [
1702
- /\/(\d+)/,
1703
- undefined,
1704
- [
1705
- {
1706
- name: 0,
1707
- prefix: "",
1708
- delimiter: "",
1709
- optional: false,
1710
- repeat: false,
1711
- pattern: ""
1712
- }
1713
- ],
1714
- [
1715
- ["/abc", null],
1716
- ["/123", ["/123", "123"]]
1717
- ],
1718
- []
1719
- ],
1720
- /**
1721
- * Mixed arrays.
1722
- */
1723
- [
1724
- ["/test", /\/(\d+)/],
1725
- undefined,
1726
- [
1727
- {
1728
- name: 0,
1729
- prefix: "",
1730
- delimiter: "",
1731
- optional: false,
1732
- repeat: false,
1733
- pattern: ""
1734
- }
1735
- ],
1736
- [["/test", ["/test", undefined]]],
1737
- []
1738
- ],
1739
- [
1740
- ["/:test(\\d+)", /(.*)/],
1741
- undefined,
1742
- [
1743
- {
1744
- name: "test",
1745
- prefix: "/",
1746
- delimiter: "/",
1747
- optional: false,
1748
- repeat: false,
1749
- pattern: "\\d+"
1750
- },
1751
- {
1752
- name: 0,
1753
- prefix: "",
1754
- delimiter: "",
1755
- optional: false,
1756
- repeat: false,
1757
- pattern: ""
1758
- }
1759
- ],
1760
- [
1761
- ["/123", ["/123", "123", undefined]],
1762
- ["/abc", ["/abc", undefined, "/abc"]]
1763
- ],
1764
- []
1765
- ],
1766
- /**
1767
- * Correct names and indexes.
1768
- */
1769
- [
1770
- ["/:test", "/route/:test"],
1771
- undefined,
1772
- [
1773
- {
1774
- name: "test",
1775
- prefix: "/",
1776
- delimiter: "/",
1777
- optional: false,
1778
- repeat: false,
1779
- pattern: "[^\\/]+?"
1780
- },
1781
- {
1782
- name: "test",
1783
- prefix: "/",
1784
- delimiter: "/",
1785
- optional: false,
1786
- repeat: false,
1787
- pattern: "[^\\/]+?"
1788
- }
1789
- ],
1790
- [
1791
- ["/test", ["/test", "test", undefined]],
1792
- ["/route/test", ["/route/test", undefined, "test"]]
1793
- ],
1794
- []
1795
- ],
1796
- [
1797
- [/^\/([^\/]+)$/, /^\/route\/([^\/]+)$/],
1798
- undefined,
1799
- [
1800
- {
1801
- name: 0,
1802
- prefix: "",
1803
- delimiter: "",
1804
- optional: false,
1805
- repeat: false,
1806
- pattern: ""
1807
- },
1808
- {
1809
- name: 0,
1810
- prefix: "",
1811
- delimiter: "",
1812
- optional: false,
1813
- repeat: false,
1814
- pattern: ""
1815
- }
1816
- ],
1817
- [
1818
- ["/test", ["/test", "test", undefined]],
1819
- ["/route/test", ["/route/test", undefined, "test"]]
1820
- ],
1821
- []
1822
- ],
1823
- /**
1824
- * Ignore non-matching groups in regexps.
1825
- */
1826
- [
1827
- /(?:.*)/,
1828
- undefined,
1829
- [],
1830
- [["/anything/you/want", ["/anything/you/want"]]],
1831
- []
1832
- ],
1833
- /**
1834
- * Respect escaped characters.
1835
- */
1836
- [
1837
- "/\\(testing\\)",
1838
- undefined,
1839
- ["/(testing)"],
1840
- [
1841
- ["/testing", null],
1842
- ["/(testing)", ["/(testing)"]]
1843
- ],
1844
- [[null, "/(testing)"]]
1845
- ],
1846
- [
1847
- "/.+*?=^!:${}[]|",
1848
- undefined,
1849
- ["/.+*?=^!:${}[]|"],
1850
- [["/.+*?=^!:${}[]|", ["/.+*?=^!:${}[]|"]]],
1851
- [[null, "/.+*?=^!:${}[]|"]]
1852
- ],
1853
- [
1854
- "/test\\/:uid(u\\d+)?:cid(c\\d+)?",
1855
- undefined,
1856
- [
1857
- "/test/",
1858
- {
1859
- name: "uid",
1860
- prefix: "",
1861
- delimiter: "/",
1862
- optional: true,
1863
- repeat: false,
1864
- pattern: "u\\d+"
1865
- },
1866
- {
1867
- name: "cid",
1868
- prefix: "",
1869
- delimiter: "/",
1870
- optional: true,
1871
- repeat: false,
1872
- pattern: "c\\d+"
1873
- }
1874
- ],
1875
- [
1876
- ["/test", null],
1877
- ["/test/", ["/test/", undefined, undefined]],
1878
- ["/test/u123", ["/test/u123", "u123", undefined]],
1879
- ["/test/c123", ["/test/c123", undefined, "c123"]]
1880
- ],
1881
- [
1882
- [{ uid: "u123" }, "/test/u123"],
1883
- [{ cid: "c123" }, "/test/c123"],
1884
- [{ cid: "u123" }, null]
1885
- ]
1886
- ],
1887
- /**
1888
- * Unnamed group prefix.
1889
- */
1890
- [
1891
- "\\/(apple-)?icon-:res(\\d+).png",
1892
- undefined,
1893
- [
1894
- "/",
1895
- {
1896
- name: 0,
1897
- prefix: "",
1898
- delimiter: "/",
1899
- optional: true,
1900
- repeat: false,
1901
- pattern: "apple-"
1902
- },
1903
- "icon",
1904
- {
1905
- name: "res",
1906
- prefix: "-",
1907
- delimiter: "-",
1908
- optional: false,
1909
- repeat: false,
1910
- pattern: "\\d+"
1911
- },
1912
- ".png"
1913
- ],
1914
- [
1915
- ["/icon-240.png", ["/icon-240.png", undefined, "240"]],
1916
- ["/apple-icon-240.png", ["/apple-icon-240.png", "apple-", "240"]]
1917
- ],
1918
- []
1919
- ],
1920
- /**
1921
- * Random examples.
1922
- */
1923
- [
1924
- "/:foo/:bar",
1925
- undefined,
1926
- [
1927
- {
1928
- name: "foo",
1929
- prefix: "/",
1930
- delimiter: "/",
1931
- optional: false,
1932
- repeat: false,
1933
- pattern: "[^\\/]+?"
1934
- },
1935
- {
1936
- name: "bar",
1937
- prefix: "/",
1938
- delimiter: "/",
1939
- optional: false,
1940
- repeat: false,
1941
- pattern: "[^\\/]+?"
1942
- }
1943
- ],
1944
- [["/match/route", ["/match/route", "match", "route"]]],
1945
- [[{ foo: "a", bar: "b" }, "/a/b"]]
1946
- ],
1947
- [
1948
- "/:foo(test\\)/bar",
1949
- undefined,
1950
- [
1951
- {
1952
- name: "foo",
1953
- prefix: "/",
1954
- delimiter: "/",
1955
- optional: false,
1956
- repeat: false,
1957
- pattern: "[^\\/]+?"
1958
- },
1959
- "(test)/bar"
1960
- ],
1961
- [],
1962
- []
1963
- ],
1964
- [
1965
- "/:remote([\\w-.]+)/:user([\\w-]+)",
1966
- undefined,
1967
- [
1968
- {
1969
- name: "remote",
1970
- prefix: "/",
1971
- delimiter: "/",
1972
- optional: false,
1973
- repeat: false,
1974
- pattern: "[\\w-.]+"
1975
- },
1976
- {
1977
- name: "user",
1978
- prefix: "/",
1979
- delimiter: "/",
1980
- optional: false,
1981
- repeat: false,
1982
- pattern: "[\\w-]+"
1983
- }
1984
- ],
1985
- [
1986
- ["/endpoint/user", ["/endpoint/user", "endpoint", "user"]],
1987
- ["/endpoint/user-name", ["/endpoint/user-name", "endpoint", "user-name"]],
1988
- ["/foo.bar/user-name", ["/foo.bar/user-name", "foo.bar", "user-name"]]
1989
- ],
1990
- [
1991
- [{ remote: "foo", user: "bar" }, "/foo/bar"],
1992
- [{ remote: "foo.bar", user: "uno" }, "/foo.bar/uno"]
1993
- ]
1994
- ],
1995
- [
1996
- "/:foo\\?",
1997
- undefined,
1998
- [
1999
- {
2000
- name: "foo",
2001
- prefix: "/",
2002
- delimiter: "/",
2003
- optional: false,
2004
- repeat: false,
2005
- pattern: "[^\\/]+?"
2006
- },
2007
- "?"
2008
- ],
2009
- [["/route?", ["/route?", "route"]]],
2010
- [[{ foo: "bar" }, "/bar?"]]
2011
- ],
2012
- [
2013
- "/:foo+baz",
2014
- undefined,
2015
- [
2016
- {
2017
- name: "foo",
2018
- prefix: "/",
2019
- delimiter: "/",
2020
- optional: false,
2021
- repeat: true,
2022
- pattern: "[^\\/]+?"
2023
- },
2024
- "baz"
2025
- ],
2026
- [
2027
- ["/foobaz", ["/foobaz", "foo"]],
2028
- ["/foo/barbaz", ["/foo/barbaz", "foo/bar"]],
2029
- ["/baz", null]
2030
- ],
2031
- [
2032
- [{ foo: "foo" }, "/foobaz"],
2033
- [{ foo: "foo/bar" }, "/foo%2Fbarbaz"],
2034
- [{ foo: ["foo", "bar"] }, "/foo/barbaz"]
2035
- ]
2036
- ],
2037
- [
2038
- "\\/:pre?baz",
2039
- undefined,
2040
- [
2041
- "/",
2042
- {
2043
- name: "pre",
2044
- prefix: "",
2045
- delimiter: "/",
2046
- optional: true,
2047
- repeat: false,
2048
- pattern: "[^\\/]+?"
2049
- },
2050
- "baz"
2051
- ],
2052
- [
2053
- ["/foobaz", ["/foobaz", "foo"]],
2054
- ["/baz", ["/baz", undefined]]
2055
- ],
2056
- [
2057
- [{}, "/baz"],
2058
- [{ pre: "foo" }, "/foobaz"]
2059
- ]
2060
- ],
2061
- [
2062
- "/:foo\\(:bar?\\)",
2063
- undefined,
2064
- [
2065
- {
2066
- name: "foo",
2067
- prefix: "/",
2068
- delimiter: "/",
2069
- optional: false,
2070
- repeat: false,
2071
- pattern: "[^\\/]+?"
2072
- },
2073
- "(",
2074
- {
2075
- name: "bar",
2076
- prefix: "",
2077
- delimiter: "/",
2078
- optional: true,
2079
- repeat: false,
2080
- pattern: "[^\\/]+?"
2081
- },
2082
- ")"
2083
- ],
2084
- [
2085
- ["/hello(world)", ["/hello(world)", "hello", "world"]],
2086
- ["/hello()", ["/hello()", "hello", undefined]]
2087
- ],
2088
- [
2089
- [{ foo: "hello", bar: "world" }, "/hello(world)"],
2090
- [{ foo: "hello" }, "/hello()"]
2091
- ]
2092
- ],
2093
- [
2094
- "/:postType(video|audio|text)(\\+.+)?",
2095
- undefined,
2096
- [
2097
- {
2098
- name: "postType",
2099
- prefix: "/",
2100
- delimiter: "/",
2101
- optional: false,
2102
- repeat: false,
2103
- pattern: "video|audio|text"
2104
- },
2105
- {
2106
- name: 0,
2107
- prefix: "",
2108
- delimiter: "/",
2109
- optional: true,
2110
- repeat: false,
2111
- pattern: "\\+.+"
2112
- }
2113
- ],
2114
- [
2115
- ["/video", ["/video", "video", undefined]],
2116
- ["/video+test", ["/video+test", "video", "+test"]],
2117
- ["/video+", null]
2118
- ],
2119
- [
2120
- [{ postType: "video" }, "/video"],
2121
- [{ postType: "random" }, null]
2122
- ]
2123
- ],
2124
- [
2125
- "/:foo?/:bar?-ext",
2126
- undefined,
2127
- [
2128
- {
2129
- name: "foo",
2130
- prefix: "/",
2131
- delimiter: "/",
2132
- optional: true,
2133
- repeat: false,
2134
- pattern: "[^\\/]+?"
2135
- },
2136
- {
2137
- name: "bar",
2138
- prefix: "/",
2139
- delimiter: "/",
2140
- optional: true,
2141
- repeat: false,
2142
- pattern: "[^\\/]+?"
2143
- },
2144
- "-ext"
2145
- ],
2146
- [
2147
- ["/-ext", null],
2148
- ["-ext", ["-ext", undefined, undefined]],
2149
- ["/foo-ext", ["/foo-ext", "foo", undefined]],
2150
- ["/foo/bar-ext", ["/foo/bar-ext", "foo", "bar"]],
2151
- ["/foo/-ext", null]
2152
- ],
2153
- [
2154
- [{}, "-ext"],
2155
- [{ foo: "foo" }, "/foo-ext"],
2156
- [{ bar: "bar" }, "/bar-ext"],
2157
- [{ foo: "foo", bar: "bar" }, "/foo/bar-ext"]
2158
- ]
2159
- ],
2160
- [
2161
- "/:required/:optional?-ext",
2162
- undefined,
2163
- [
2164
- {
2165
- name: "required",
2166
- prefix: "/",
2167
- delimiter: "/",
2168
- optional: false,
2169
- repeat: false,
2170
- pattern: "[^\\/]+?"
2171
- },
2172
- {
2173
- name: "optional",
2174
- prefix: "/",
2175
- delimiter: "/",
2176
- optional: true,
2177
- repeat: false,
2178
- pattern: "[^\\/]+?"
2179
- },
2180
- "-ext"
2181
- ],
2182
- [
2183
- ["/foo-ext", ["/foo-ext", "foo", undefined]],
2184
- ["/foo/bar-ext", ["/foo/bar-ext", "foo", "bar"]],
2185
- ["/foo/-ext", null]
2186
- ],
2187
- [
2188
- [{ required: "foo" }, "/foo-ext"],
2189
- [{ required: "foo", optional: "baz" }, "/foo/baz-ext"]
2190
- ]
2191
- ],
2192
- /**
2193
- * Unicode characters.
2194
- */
2195
- [
2196
- "/:foo",
2197
- undefined,
2198
- [
2199
- {
2200
- name: "foo",
2201
- prefix: "/",
2202
- delimiter: "/",
2203
- optional: false,
2204
- repeat: false,
2205
- pattern: "[^\\/]+?"
2206
- }
2207
- ],
2208
- [["/café", ["/café", "café"]]],
2209
- [[{ foo: "café" }, "/caf%C3%A9"]]
2210
- ],
2211
- ["/café", undefined, ["/café"], [["/café", ["/café"]]], [[null, "/café"]]],
2212
- [
2213
- "packages/",
2214
- undefined,
2215
- ["packages/"],
2216
- [
2217
- ["packages", null],
2218
- ["packages/", ["packages/"]]
2219
- ],
2220
- [[null, "packages/"]]
2221
- ],
2222
- /**
2223
- * Hostnames.
2224
- */
2225
- [
2226
- ":domain.com",
2227
- {
2228
- delimiter: "."
2229
- },
2230
- [
2231
- {
2232
- name: "domain",
2233
- prefix: "",
2234
- delimiter: ".",
2235
- optional: false,
2236
- repeat: false,
2237
- pattern: "[^\\.]+?"
2238
- },
2239
- ".com"
2240
- ],
2241
- [
2242
- ["example.com", ["example.com", "example"]],
2243
- ["github.com", ["github.com", "github"]]
2244
- ],
2245
- [
2246
- [{ domain: "example" }, "example.com"],
2247
- [{ domain: "github" }, "github.com"]
2248
- ]
2249
- ],
2250
- [
2251
- "mail.:domain.com",
2252
- {
2253
- delimiter: "."
2254
- },
2255
- [
2256
- "mail",
2257
- {
2258
- name: "domain",
2259
- prefix: ".",
2260
- delimiter: ".",
2261
- optional: false,
2262
- repeat: false,
2263
- pattern: "[^\\.]+?"
2264
- },
2265
- ".com"
2266
- ],
2267
- [
2268
- ["mail.example.com", ["mail.example.com", "example"]],
2269
- ["mail.github.com", ["mail.github.com", "github"]]
2270
- ],
2271
- [
2272
- [{ domain: "example" }, "mail.example.com"],
2273
- [{ domain: "github" }, "mail.github.com"]
2274
- ]
2275
- ],
2276
- [
2277
- "example.:ext",
2278
- {
2279
- delimiter: "."
2280
- },
2281
- [
2282
- "example",
2283
- {
2284
- name: "ext",
2285
- prefix: ".",
2286
- delimiter: ".",
2287
- optional: false,
2288
- repeat: false,
2289
- pattern: "[^\\.]+?"
2290
- }
2291
- ],
2292
- [
2293
- ["example.com", ["example.com", "com"]],
2294
- ["example.org", ["example.org", "org"]]
2295
- ],
2296
- [
2297
- [{ ext: "com" }, "example.com"],
2298
- [{ ext: "org" }, "example.org"]
2299
- ]
2300
- ],
2301
- [
2302
- "this is",
2303
- {
2304
- delimiter: " ",
2305
- end: false
2306
- },
2307
- ["this is"],
2308
- [
2309
- ["this is a test", ["this is"]],
2310
- ["this isn't", null]
2311
- ],
2312
- [[null, "this is"]]
2313
- ],
2314
- /**
2315
- * Ends with.
2316
- */
2317
- [
2318
- "/test",
2319
- {
2320
- endsWith: "?"
2321
- },
2322
- ["/test"],
2323
- [
2324
- ["/test", ["/test"]],
2325
- ["/test?query=string", ["/test"]],
2326
- ["/test/?query=string", ["/test/"]],
2327
- ["/testx", null]
2328
- ],
2329
- [[null, "/test"]]
2330
- ],
2331
- [
2332
- "/test",
2333
- {
2334
- endsWith: "?",
2335
- strict: true
2336
- },
2337
- ["/test"],
2338
- [
2339
- ["/test?query=string", ["/test"]],
2340
- ["/test/?query=string", null]
2341
- ],
2342
- [[null, "/test"]]
2343
- ],
2344
- /**
2345
- * Custom delimiters.
2346
- */
2347
- [
2348
- "$:foo$:bar?",
2349
- {
2350
- delimiter: "$"
2351
- },
2352
- [
2353
- {
2354
- delimiter: "$",
2355
- name: "foo",
2356
- optional: false,
2357
- pattern: "[^\\$]+?",
2358
- prefix: "$",
2359
- repeat: false
2360
- },
2361
- {
2362
- delimiter: "$",
2363
- name: "bar",
2364
- optional: true,
2365
- pattern: "[^\\$]+?",
2366
- prefix: "$",
2367
- repeat: false
2368
- }
2369
- ],
2370
- [
2371
- ["$x", ["$x", "x", undefined]],
2372
- ["$x$y", ["$x$y", "x", "y"]]
2373
- ],
2374
- [
2375
- [{ foo: "foo" }, "$foo"],
2376
- [{ foo: "foo", bar: "bar" }, "$foo$bar"]
2377
- ]
2378
- ],
2379
- [
2380
- ":test+",
2381
- {
2382
- delimiter: " "
2383
- },
2384
- [
2385
- {
2386
- name: "test",
2387
- prefix: "",
2388
- delimiter: " ",
2389
- optional: false,
2390
- repeat: true,
2391
- pattern: "[^ ]+?"
2392
- }
2393
- ],
2394
- [
2395
- ["hello", ["hello", "hello"]],
2396
- [" hello ", null],
2397
- ["", null],
2398
- ["hello world", ["hello world", "hello world"]]
2399
- ],
2400
- [
2401
- [{}, null],
2402
- [{ test: "" }, null],
2403
- [{ test: ["hello"] }, "hello"],
2404
- [{ test: ["hello", "world"] }, "hello world"]
2405
- ]
2406
- ],
2407
- [
2408
- "name/:attr1?-:attr2?-:attr3?",
2409
- {},
2410
- [
2411
- "name",
2412
- {
2413
- delimiter: "/",
2414
- name: "attr1",
2415
- optional: true,
2416
- pattern: "[^\\/]+?",
2417
- prefix: "/",
2418
- repeat: false
2419
- },
2420
- {
2421
- delimiter: "-",
2422
- name: "attr2",
2423
- optional: true,
2424
- pattern: "[^-\\/]+?",
2425
- prefix: "-",
2426
- repeat: false
2427
- },
2428
- {
2429
- delimiter: "-",
2430
- name: "attr3",
2431
- optional: true,
2432
- pattern: "[^-\\/]+?",
2433
- prefix: "-",
2434
- repeat: false
2435
- }
2436
- ],
2437
- [
2438
- ["name/test", ["name/test", "test", undefined, undefined]],
2439
- ["name/1", ["name/1", "1", undefined, undefined]],
2440
- ["name/1-2", ["name/1-2", "1", "2", undefined]],
2441
- ["name/1-2-3", ["name/1-2-3", "1", "2", "3"]],
2442
- ["name/foo-bar/route", null],
2443
- ["name/test/route", null]
2444
- ],
2445
- [
2446
- [{}, "name"],
2447
- [{ attr1: "test" }, "name/test"],
2448
- [{ attr2: "attr" }, "name-attr"]
2449
- ]
2450
- ],
2451
- [
2452
- "name/:attr1?-:attr2?",
2453
- {
2454
- whitelist: "/"
2455
- },
2456
- [
2457
- "name",
2458
- {
2459
- delimiter: "/",
2460
- name: "attr1",
2461
- optional: true,
2462
- pattern: "[^\\/]+?",
2463
- prefix: "/",
2464
- repeat: false
2465
- },
2466
- "-",
2467
- {
2468
- delimiter: "/",
2469
- name: "attr2",
2470
- optional: true,
2471
- pattern: "[^\\/]+?",
2472
- prefix: "",
2473
- repeat: false
2474
- }
2475
- ],
2476
- [
2477
- ["name/1", null],
2478
- ["name/1-", ["name/1-", "1", undefined]],
2479
- ["name/1-2", ["name/1-2", "1", "2"]],
2480
- ["name/1-2-3", ["name/1-2-3", "1", "2-3"]],
2481
- ["name/foo-bar/route", null],
2482
- ["name/test/route", null]
2483
- ],
2484
- [
2485
- [{}, "name-"],
2486
- [{ attr1: "test" }, "name/test-"],
2487
- [{ attr2: "attr" }, "name-attr"]
2488
- ]
2489
- ],
2490
- /**
2491
- * Case-sensitive compile tokensToFunction params.
2492
- */
2493
- [
2494
- "/:test(abc)",
2495
- {
2496
- sensitive: true
2497
- },
2498
- [
2499
- {
2500
- name: "test",
2501
- prefix: "/",
2502
- delimiter: "/",
2503
- optional: false,
2504
- repeat: false,
2505
- pattern: "abc"
2506
- }
2507
- ],
2508
- [
2509
- ["/abc", ["/abc", "abc"]],
2510
- ["/ABC", null]
2511
- ],
2512
- [
2513
- [{ test: "abc" }, "/abc"],
2514
- [{ test: "ABC" }, null]
2515
- ]
2516
- ],
2517
- [
2518
- "/:test(abc)",
2519
- {},
2520
- [
2521
- {
2522
- name: "test",
2523
- prefix: "/",
2524
- delimiter: "/",
2525
- optional: false,
2526
- repeat: false,
2527
- pattern: "abc"
2528
- }
2529
- ],
2530
- [
2531
- ["/abc", ["/abc", "abc"]],
2532
- ["/ABC", ["/ABC", "ABC"]]
2533
- ],
2534
- [
2535
- [{ test: "abc" }, "/abc"],
2536
- [{ test: "ABC" }, "/ABC"]
2537
- ]
2538
- ],
2539
- /**
2540
- * Nested parentheses.
2541
- */
2542
- [
2543
- "/:test(\\d+(?:\\.\\d+)?)",
2544
- undefined,
2545
- [
2546
- {
2547
- name: "test",
2548
- prefix: "/",
2549
- delimiter: "/",
2550
- optional: false,
2551
- repeat: false,
2552
- pattern: "\\d+(?:\\.\\d+)?"
2553
- }
2554
- ],
2555
- [
2556
- ["/123", ["/123", "123"]],
2557
- ["/abc", null],
2558
- ["/123/abc", null],
2559
- ["/123.123", ["/123.123", "123.123"]],
2560
- ["/123.abc", null]
2561
- ],
2562
- [
2563
- [{ test: 123 }, "/123"],
2564
- [{ test: 123.123 }, "/123.123"],
2565
- [{ test: "abc" }, null],
2566
- [{ test: "123" }, "/123"],
2567
- [{ test: "123.123" }, "/123.123"],
2568
- [{ test: "123.abc" }, null]
2569
- ]
2570
- ],
2571
- [
2572
- "/:test((?!login)[^/]+)",
2573
- undefined,
2574
- [
2575
- {
2576
- name: "test",
2577
- prefix: "/",
2578
- delimiter: "/",
2579
- optional: false,
2580
- repeat: false,
2581
- pattern: "(?!login)[^/]+"
2582
- }
2583
- ],
2584
- [
2585
- ["/route", ["/route", "route"]],
2586
- ["/login", null]
2587
- ],
2588
- [
2589
- [{ test: "route" }, "/route"],
2590
- [{ test: "login" }, null]
2591
- ]
2592
- ]
2593
- ];
2594
- /**
2595
- * Dynamically generate the entire test suite.
2596
- */
2597
- describe("path-to-regexp", function () {
2598
- var TEST_PATH = "/user/:id";
2599
- var TEST_PARAM = {
2600
- name: "id",
2601
- prefix: "/",
2602
- delimiter: "/",
2603
- optional: false,
2604
- repeat: false,
2605
- pattern: "[^\\/]+?"
2606
- };
2607
- describe("arguments", function () {
2608
- it("should work without different call combinations", function () {
2609
- pathToRegexp.pathToRegexp("/test");
2610
- pathToRegexp.pathToRegexp("/test", []);
2611
- pathToRegexp.pathToRegexp("/test", undefined, {});
2612
- pathToRegexp.pathToRegexp(/^\/test/);
2613
- pathToRegexp.pathToRegexp(/^\/test/, []);
2614
- pathToRegexp.pathToRegexp(/^\/test/, undefined, {});
2615
- pathToRegexp.pathToRegexp(["/a", "/b"]);
2616
- pathToRegexp.pathToRegexp(["/a", "/b"], []);
2617
- pathToRegexp.pathToRegexp(["/a", "/b"], undefined, {});
2618
- });
2619
- it("should accept an array of keys as the second argument", function () {
2620
- var keys = [];
2621
- var re = pathToRegexp.pathToRegexp(TEST_PATH, keys, { end: false });
2622
- expect(keys).toEqual([TEST_PARAM]);
2623
- expect(exec(re, "/user/123/show")).toEqual(["/user/123", "123"]);
2624
- });
2625
- it("should throw on non-capturing pattern group", function () {
2626
- expect(function () {
2627
- pathToRegexp.pathToRegexp("/:foo(?:\\d+(\\.\\d+)?)");
2628
- }).toThrow(new TypeError("Path pattern must be a capturing group"));
2629
- });
2630
- it("should throw on nested capturing regexp groups", function () {
2631
- expect(function () {
2632
- pathToRegexp.pathToRegexp("/:foo(\\d+(\\.\\d+)?)");
2633
- }).toThrow(new TypeError("Capturing groups are not allowed in pattern, use a non-capturing group: (\\d+(?:\\.\\d+)?)"));
2634
- });
2635
- });
2636
- describe("tokens", function () {
2637
- var tokens = pathToRegexp.parse(TEST_PATH);
2638
- it("should expose method to compile tokens to regexp", function () {
2639
- var re = pathToRegexp.tokensToRegexp(tokens);
2640
- expect(exec(re, "/user/123")).toEqual(["/user/123", "123"]);
2641
- });
2642
- it("should expose method to compile tokens to a path function", function () {
2643
- var fn = pathToRegexp.tokensToFunction(tokens);
2644
- expect(fn({ id: 123 })).toEqual("/user/123");
2645
- });
2646
- });
2647
- describe("rules", function () {
2648
- TESTS.forEach(function (test) {
2649
- var path = test[0], opts = test[1], tokens = test[2], matchCases = test[3], compileCases = test[4];
2650
- describe(util.inspect(path), function () {
2651
- var keys = [];
2652
- var re = pathToRegexp.pathToRegexp(path, keys, opts);
2653
- // Parsing and compiling is only supported with string input.
2654
- if (typeof path === "string") {
2655
- it("should parse", function () {
2656
- expect(pathToRegexp.parse(path, opts)).toEqual(tokens);
2657
- });
2658
- describe("compile", function () {
2659
- compileCases.forEach(function (io) {
2660
- var params = io[0], result = io[1], options = io[2];
2661
- var toPath = pathToRegexp.compile(path, __assign(__assign({}, opts), options));
2662
- if (result !== null) {
2663
- it("should compile using " + util.inspect(params), function () {
2664
- expect(toPath(params)).toEqual(result);
2665
- });
2666
- }
2667
- else {
2668
- it("should not compile using " + util.inspect(params), function () {
2669
- expect(function () {
2670
- toPath(params);
2671
- }).toThrow(TypeError);
2672
- });
2673
- }
2674
- });
2675
- });
2676
- }
2677
- else {
2678
- it("should parse keys", function () {
2679
- expect(keys).toEqual(tokens.filter(function (token) {
2680
- return typeof token !== "string";
2681
- }));
2682
- });
2683
- }
2684
- describe("match" + (opts ? " using " + util.inspect(opts) : ""), function () {
2685
- matchCases.forEach(function (io) {
2686
- var pathname = io[0], matches = io[1], params = io[2], options = io[3];
2687
- var message = "should " + (matches ? "" : "not ") + "match " + util.inspect(pathname);
2688
- it(message, function () {
2689
- expect(exec(re, pathname)).toEqual(matches);
2690
- });
2691
- if (typeof path === "string" && params !== undefined) {
2692
- var match_1 = pathToRegexp.match(path, options);
2693
- it(message + " params", function () {
2694
- expect(match_1(pathname)).toEqual(params);
2695
- });
2696
- }
2697
- });
2698
- });
2699
- });
2700
- });
2701
- });
2702
- describe("compile errors", function () {
2703
- it("should throw when a required param is undefined", function () {
2704
- var toPath = pathToRegexp.compile("/a/:b/c");
2705
- expect(function () {
2706
- toPath();
2707
- }).toThrow(new TypeError('Expected "b" to be a string'));
2708
- });
2709
- it("should throw when it does not match the pattern", function () {
2710
- var toPath = pathToRegexp.compile("/:foo(\\d+)");
2711
- expect(function () {
2712
- toPath({ foo: "abc" });
2713
- }).toThrow(new TypeError('Expected "foo" to match "\\d+", but got "abc"'));
2714
- });
2715
- it("should throw when expecting a repeated value", function () {
2716
- var toPath = pathToRegexp.compile("/:foo+");
2717
- expect(function () {
2718
- toPath({ foo: [] });
2719
- }).toThrow(new TypeError('Expected "foo" to not be empty'));
2720
- });
2721
- it("should throw when not expecting a repeated value", function () {
2722
- var toPath = pathToRegexp.compile("/:foo");
2723
- expect(function () {
2724
- toPath({ foo: [] });
2725
- }).toThrow(new TypeError('Expected "foo" to not repeat, but got an array'));
2726
- });
2727
- it("should throw when repeated value does not match", function () {
2728
- var toPath = pathToRegexp.compile("/:foo(\\d+)+");
2729
- expect(function () {
2730
- toPath({ foo: [1, 2, 3, "a"] });
2731
- }).toThrow(new TypeError('Expected all "foo" to match "\\d+", but got "a"'));
2732
- });
2733
- });
2734
- describe("normalize pathname", function () {
2735
- it("should match normalized pathnames", function () {
2736
- var re = pathToRegexp.pathToRegexp("/caf\u00E9");
2737
- var input = encodeURI("/cafe\u0301");
2738
- expect(exec(re, input)).toEqual(null);
2739
- expect(exec(re, pathToRegexp.normalizePathname(input).normalize())).toEqual(["/caf\u00E9"]);
2740
- });
2741
- it("should not normalize encoded slash", function () {
2742
- var input = "/test/route%2F";
2743
- expect(pathToRegexp.normalizePathname(input)).toEqual("/test/route%2F");
2744
- });
2745
- it("should fix repeated slashes", function () {
2746
- var input = encodeURI("/test///route");
2747
- expect(pathToRegexp.normalizePathname(input)).toEqual("/test/route");
2748
- });
2749
- });
2750
- });
2751
- /**
2752
- * Execute a regular expression and return a flat array for comparison.
2753
- *
2754
- * @param {RegExp} re
2755
- * @param {String} str
2756
- * @return {Array}
2757
- */
2758
- function exec(re, str) {
2759
- var match = re.exec(str);
2760
- return match && Array.prototype.slice.call(match);
2761
- }
2762
- //# sourceMappingURL=index.spec.js.map