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