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