@@ -1298,6 +1298,40 @@ func TestRouterParam1466(t *testing.T) {
1298
1298
assert .Equal (t , 0 , c .response .Status )
1299
1299
}
1300
1300
1301
+ // Issue #1653
1302
+ func TestRouterPanicWhenParamNoRootOnlyChildsFailsFind (t * testing.T ) {
1303
+ e := New ()
1304
+ r := e .router
1305
+
1306
+ r .Add (http .MethodGet , "/users/create" , handlerHelper ("create" , 1 ))
1307
+ r .Add (http .MethodGet , "/users/:id/edit" , func (c Context ) error {
1308
+ return nil
1309
+ })
1310
+ r .Add (http .MethodGet , "/users/:id/active" , func (c Context ) error {
1311
+ return nil
1312
+ })
1313
+
1314
+ c := e .NewContext (nil , nil ).(* context )
1315
+ r .Find (http .MethodGet , "/users/alice/edit" , c )
1316
+ assert .Equal (t , "alice" , c .Param ("id" ))
1317
+
1318
+ c = e .NewContext (nil , nil ).(* context )
1319
+ r .Find (http .MethodGet , "/users/bob/active" , c )
1320
+ assert .Equal (t , "bob" , c .Param ("id" ))
1321
+
1322
+ c = e .NewContext (nil , nil ).(* context )
1323
+ r .Find (http .MethodGet , "/users/create" , c )
1324
+ c .Handler ()(c )
1325
+ assert .Equal (t , 1 , c .Get ("create" ))
1326
+ assert .Equal (t , "/users/create" , c .Get ("path" ))
1327
+
1328
+ //This panic before the fix for Issue #1653
1329
+ c = e .NewContext (nil , nil ).(* context )
1330
+ r .Find (http .MethodGet , "/users/createNotFound" , c )
1331
+ he := c .Handler ()(c ).(* HTTPError )
1332
+ assert .Equal (t , http .StatusNotFound , he .Code )
1333
+ }
1334
+
1301
1335
func benchmarkRouterRoutes (b * testing.B , routes []* Route ) {
1302
1336
e := New ()
1303
1337
r := e .router
0 commit comments