@@ -958,6 +958,74 @@ func TestRouterList(t *testing.T) {
958
958
959
959
}
960
960
961
+ func TestRouterSamePrefixParamRoute (t * testing.T ) {
962
+ var id1 , id2 , id3 , pageSize , page , iid string
963
+ var routed1 , routed2 , routed3 bool
964
+
965
+ r := New ()
966
+ v1 := r .Group ("/v1" )
967
+ v1 .GET ("/foo/{id}/{pageSize}/{page}" , func (ctx * fasthttp.RequestCtx ) {
968
+ id1 = ctx .UserValue ("id" ).(string )
969
+ pageSize = ctx .UserValue ("pageSize" ).(string )
970
+ page = ctx .UserValue ("page" ).(string )
971
+ routed1 = true
972
+ })
973
+ v1 .GET ("/foo/{id}/{iid}" , func (ctx * fasthttp.RequestCtx ) {
974
+ id2 = ctx .UserValue ("id" ).(string )
975
+ iid = ctx .UserValue ("iid" ).(string )
976
+ routed2 = true
977
+ })
978
+ v1 .GET ("/foo/{id}" , func (ctx * fasthttp.RequestCtx ) {
979
+ id3 = ctx .UserValue ("id" ).(string )
980
+ routed3 = true
981
+ })
982
+
983
+ req := new (fasthttp.RequestCtx )
984
+ req .Request .SetRequestURI ("/v1/foo/1/20/4" )
985
+ r .Handler (req )
986
+ req = new (fasthttp.RequestCtx )
987
+ req .Request .SetRequestURI ("/v1/foo/2/3" )
988
+ r .Handler (req )
989
+ req = new (fasthttp.RequestCtx )
990
+ req .Request .SetRequestURI ("/v1/foo/v3" )
991
+ r .Handler (req )
992
+
993
+ if ! routed1 {
994
+ t .Error ("/foo/{id}/{pageSize}/{page} not routed." )
995
+ }
996
+ if ! routed2 {
997
+ t .Error ("/foo/{id}/{iid} not routed" )
998
+ }
999
+
1000
+ if ! routed3 {
1001
+ t .Error ("/foo/{id} not routed" )
1002
+ }
1003
+
1004
+ if id1 != "1" {
1005
+ t .Errorf ("/foo/{id}/{pageSize}/{page} id expect: 1 got %s" , id1 )
1006
+ }
1007
+
1008
+ if pageSize != "20" {
1009
+ t .Errorf ("/foo/{id}/{pageSize}/{page} pageSize expect: 20 got %s" , pageSize )
1010
+ }
1011
+
1012
+ if page != "4" {
1013
+ t .Errorf ("/foo/{id}/{pageSize}/{page} page expect: 4 got %s" , page )
1014
+ }
1015
+
1016
+ if id2 != "2" {
1017
+ t .Errorf ("/foo/{id}/{iid} id expect: 2 got %s" , id2 )
1018
+ }
1019
+
1020
+ if iid != "3" {
1021
+ t .Errorf ("/foo/{id}/{iid} iid expect: 3 got %s" , iid )
1022
+ }
1023
+
1024
+ if id3 != "v3" {
1025
+ t .Errorf ("/foo/{id} id expect: v3 got %s" , id3 )
1026
+ }
1027
+ }
1028
+
961
1029
func BenchmarkAllowed (b * testing.B ) {
962
1030
handlerFunc := func (_ * fasthttp.RequestCtx ) {}
963
1031
0 commit comments