@@ -189,7 +189,7 @@ describe('app.router', function(){
189
189
. expect ( 'editing user 10' , done ) ;
190
190
} )
191
191
192
- it . skip ( 'should ensure regexp matches path prefix' , function ( done ) {
192
+ it ( 'should ensure regexp matches path prefix' , function ( done ) {
193
193
var app = express ( )
194
194
var p = [ ]
195
195
@@ -315,7 +315,7 @@ describe('app.router', function(){
315
315
var app = express ( ) ;
316
316
var router = new express . Router ( { mergeParams : true } ) ;
317
317
318
- router . get ( '/*.* ' , function ( req , res ) {
318
+ router . get ( '/(.*).(.*) ' , function ( req , res ) {
319
319
var keys = Object . keys ( req . params ) . sort ( ) ;
320
320
res . send ( keys . map ( function ( k ) { return [ k , req . params [ k ] ] } ) ) ;
321
321
} ) ;
@@ -331,7 +331,7 @@ describe('app.router', function(){
331
331
var app = express ( ) ;
332
332
var router = new express . Router ( { mergeParams : true } ) ;
333
333
334
- router . get ( '/* ' , function ( req , res ) {
334
+ router . get ( '/(.*) ' , function ( req , res ) {
335
335
var keys = Object . keys ( req . params ) . sort ( ) ;
336
336
res . send ( keys . map ( function ( k ) { return [ k , req . params [ k ] ] } ) ) ;
337
337
} ) ;
@@ -553,23 +553,6 @@ describe('app.router', function(){
553
553
} )
554
554
} )
555
555
556
- it ( 'should allow escaped regexp' , function ( done ) {
557
- var app = express ( ) ;
558
-
559
- app . get ( '/user/\\d+' , function ( req , res ) {
560
- res . end ( 'woot' ) ;
561
- } ) ;
562
-
563
- request ( app )
564
- . get ( '/user/10' )
565
- . expect ( 200 , function ( err ) {
566
- if ( err ) return done ( err )
567
- request ( app )
568
- . get ( '/user/tj' )
569
- . expect ( 404 , done ) ;
570
- } ) ;
571
- } )
572
-
573
556
it ( 'should allow literal "."' , function ( done ) {
574
557
var app = express ( ) ;
575
558
@@ -585,171 +568,6 @@ describe('app.router', function(){
585
568
. expect ( 'users from 1 to 50' , done ) ;
586
569
} )
587
570
588
- describe ( '*' , function ( ) {
589
- it ( 'should capture everything' , function ( done ) {
590
- var app = express ( )
591
-
592
- app . get ( '*' , function ( req , res ) {
593
- res . end ( req . params [ 0 ] )
594
- } )
595
-
596
- request ( app )
597
- . get ( '/user/tobi.json' )
598
- . expect ( '/user/tobi.json' , done )
599
- } )
600
-
601
- it ( 'should decode the capture' , function ( done ) {
602
- var app = express ( )
603
-
604
- app . get ( '*' , function ( req , res ) {
605
- res . end ( req . params [ 0 ] )
606
- } )
607
-
608
- request ( app )
609
- . get ( '/user/tobi%20and%20loki.json' )
610
- . expect ( '/user/tobi and loki.json' , done )
611
- } )
612
-
613
- it ( 'should denote a greedy capture group' , function ( done ) {
614
- var app = express ( ) ;
615
-
616
- app . get ( '/user/*.json' , function ( req , res ) {
617
- res . end ( req . params [ 0 ] ) ;
618
- } ) ;
619
-
620
- request ( app )
621
- . get ( '/user/tj.json' )
622
- . expect ( 'tj' , done ) ;
623
- } )
624
-
625
- it ( 'should work with several' , function ( done ) {
626
- var app = express ( ) ;
627
-
628
- app . get ( '/api/*.*' , function ( req , res ) {
629
- var resource = req . params [ 0 ]
630
- , format = req . params [ 1 ] ;
631
- res . end ( resource + ' as ' + format ) ;
632
- } ) ;
633
-
634
- request ( app )
635
- . get ( '/api/users/foo.bar.json' )
636
- . expect ( 'users/foo.bar as json' , done ) ;
637
- } )
638
-
639
- it ( 'should work cross-segment' , function ( done ) {
640
- var app = express ( ) ;
641
-
642
- app . get ( '/api*' , function ( req , res ) {
643
- res . send ( req . params [ 0 ] ) ;
644
- } ) ;
645
-
646
- request ( app )
647
- . get ( '/api' )
648
- . expect ( '' , function ( ) {
649
- request ( app )
650
- . get ( '/api/hey' )
651
- . expect ( '/hey' , done ) ;
652
- } ) ;
653
- } )
654
-
655
- it ( 'should allow naming' , function ( done ) {
656
- var app = express ( ) ;
657
-
658
- app . get ( '/api/:resource(*)' , function ( req , res ) {
659
- var resource = req . params . resource ;
660
- res . end ( resource ) ;
661
- } ) ;
662
-
663
- request ( app )
664
- . get ( '/api/users/0.json' )
665
- . expect ( 'users/0.json' , done ) ;
666
- } )
667
-
668
- it ( 'should not be greedy immediately after param' , function ( done ) {
669
- var app = express ( ) ;
670
-
671
- app . get ( '/user/:user*' , function ( req , res ) {
672
- res . end ( req . params . user ) ;
673
- } ) ;
674
-
675
- request ( app )
676
- . get ( '/user/122' )
677
- . expect ( '122' , done ) ;
678
- } )
679
-
680
- it ( 'should eat everything after /' , function ( done ) {
681
- var app = express ( ) ;
682
-
683
- app . get ( '/user/:user*' , function ( req , res ) {
684
- res . end ( req . params . user ) ;
685
- } ) ;
686
-
687
- request ( app )
688
- . get ( '/user/122/aaa' )
689
- . expect ( '122' , done ) ;
690
- } )
691
-
692
- it ( 'should span multiple segments' , function ( done ) {
693
- var app = express ( ) ;
694
-
695
- app . get ( '/file/*' , function ( req , res ) {
696
- res . end ( req . params [ 0 ] ) ;
697
- } ) ;
698
-
699
- request ( app )
700
- . get ( '/file/javascripts/jquery.js' )
701
- . expect ( 'javascripts/jquery.js' , done ) ;
702
- } )
703
-
704
- it ( 'should be optional' , function ( done ) {
705
- var app = express ( ) ;
706
-
707
- app . get ( '/file/*' , function ( req , res ) {
708
- res . end ( req . params [ 0 ] ) ;
709
- } ) ;
710
-
711
- request ( app )
712
- . get ( '/file/' )
713
- . expect ( '' , done ) ;
714
- } )
715
-
716
- it ( 'should require a preceding /' , function ( done ) {
717
- var app = express ( ) ;
718
-
719
- app . get ( '/file/*' , function ( req , res ) {
720
- res . end ( req . params [ 0 ] ) ;
721
- } ) ;
722
-
723
- request ( app )
724
- . get ( '/file' )
725
- . expect ( 404 , done ) ;
726
- } )
727
-
728
- it ( 'should keep correct parameter indexes' , function ( done ) {
729
- var app = express ( ) ;
730
-
731
- app . get ( '/*/user/:id' , function ( req , res ) {
732
- res . send ( req . params ) ;
733
- } ) ;
734
-
735
- request ( app )
736
- . get ( '/1/user/2' )
737
- . expect ( 200 , '{"0":"1","id":"2"}' , done ) ;
738
- } )
739
-
740
- it ( 'should work within arrays' , function ( done ) {
741
- var app = express ( ) ;
742
-
743
- app . get ( [ '/user/:id' , '/foo/*' , '/:bar' ] , function ( req , res ) {
744
- res . send ( req . params . bar ) ;
745
- } ) ;
746
-
747
- request ( app )
748
- . get ( '/test' )
749
- . expect ( 200 , 'test' , done ) ;
750
- } )
751
- } )
752
-
753
571
describe ( ':name' , function ( ) {
754
572
it ( 'should denote a capture group' , function ( done ) {
755
573
var app = express ( ) ;
@@ -791,7 +609,7 @@ describe('app.router', function(){
791
609
var app = express ( ) ;
792
610
var cb = after ( 2 , done ) ;
793
611
794
- app . get ( '/user(s)? /:user/:op' , function ( req , res ) {
612
+ app . get ( '/user(s?) /:user/:op' , function ( req , res ) {
795
613
res . end ( req . params . op + 'ing ' + req . params . user + ( req . params [ 0 ] ? ' (old)' : '' ) ) ;
796
614
} ) ;
797
615
@@ -862,6 +680,82 @@ describe('app.router', function(){
862
680
} )
863
681
} )
864
682
683
+ describe ( ':name*' , function ( ) {
684
+ it ( 'should match one segment' , function ( done ) {
685
+ var app = express ( )
686
+
687
+ app . get ( '/user/:user*' , function ( req , res ) {
688
+ res . end ( req . params . user )
689
+ } )
690
+
691
+ request ( app )
692
+ . get ( '/user/122' )
693
+ . expect ( '122' , done )
694
+ } )
695
+
696
+ it ( 'should match many segments' , function ( done ) {
697
+ var app = express ( )
698
+
699
+ app . get ( '/user/:user*' , function ( req , res ) {
700
+ res . end ( req . params . user )
701
+ } )
702
+
703
+ request ( app )
704
+ . get ( '/user/1/2/3/4' )
705
+ . expect ( '1/2/3/4' , done )
706
+ } )
707
+
708
+ it ( 'should match zero segments' , function ( done ) {
709
+ var app = express ( )
710
+
711
+ app . get ( '/user/:user*' , function ( req , res ) {
712
+ res . end ( req . params . user )
713
+ } )
714
+
715
+ request ( app )
716
+ . get ( '/user' )
717
+ . expect ( '' , done )
718
+ } )
719
+ } )
720
+
721
+ describe ( ':name+' , function ( ) {
722
+ it ( 'should match one segment' , function ( done ) {
723
+ var app = express ( )
724
+
725
+ app . get ( '/user/:user+' , function ( req , res ) {
726
+ res . end ( req . params . user )
727
+ } )
728
+
729
+ request ( app )
730
+ . get ( '/user/122' )
731
+ . expect ( 200 , '122' , done )
732
+ } )
733
+
734
+ it ( 'should match many segments' , function ( done ) {
735
+ var app = express ( )
736
+
737
+ app . get ( '/user/:user+' , function ( req , res ) {
738
+ res . end ( req . params . user )
739
+ } )
740
+
741
+ request ( app )
742
+ . get ( '/user/1/2/3/4' )
743
+ . expect ( 200 , '1/2/3/4' , done )
744
+ } )
745
+
746
+ it ( 'should not match zero segments' , function ( done ) {
747
+ var app = express ( )
748
+
749
+ app . get ( '/user/:user+' , function ( req , res ) {
750
+ res . end ( req . params . user )
751
+ } )
752
+
753
+ request ( app )
754
+ . get ( '/user' )
755
+ . expect ( 404 , done )
756
+ } )
757
+ } )
758
+
865
759
describe ( '.:name' , function ( ) {
866
760
it ( 'should denote a format' , function ( done ) {
867
761
var app = express ( ) ;
@@ -1199,7 +1093,7 @@ describe('app.router', function(){
1199
1093
var app = express ( ) ;
1200
1094
var path = [ ] ;
1201
1095
1202
- app . get ( '* ' , function ( req , res , next ) {
1096
+ app . get ( '/:path+ ' , function ( req , res , next ) {
1203
1097
path . push ( 0 ) ;
1204
1098
next ( ) ;
1205
1099
} ) ;
@@ -1219,7 +1113,7 @@ describe('app.router', function(){
1219
1113
next ( ) ;
1220
1114
} ) ;
1221
1115
1222
- app . get ( '* ' , function ( req , res , next ) {
1116
+ app . get ( '/(.*) ' , function ( req , res , next ) {
1223
1117
path . push ( 4 ) ;
1224
1118
next ( ) ;
1225
1119
} ) ;
0 commit comments