@@ -335,16 +335,6 @@ func TestPath(t *testing.T) {
335
335
pathTemplate : `/111/{v1:[0-9]{3}}/333` ,
336
336
shouldMatch : false ,
337
337
},
338
- {
339
- title : "Path route, URL with encoded slash does match" ,
340
- route : new (Route ).Path ("/v1/{v1}/v2" ),
341
- request : newRequest ("GET" , "http://localhost/v1/1%2F2/v2" ),
342
- vars : map [string ]string {"v1" : "1%2F2" },
343
- host : "" ,
344
- path : "/v1/1%2F2/v2" ,
345
- pathTemplate : `/v1/{v1}/v2` ,
346
- shouldMatch : true ,
347
- },
348
338
{
349
339
title : "Path route with multiple patterns, match" ,
350
340
route : new (Route ).Path ("/{v1:[0-9]{3}}/{v2:[0-9]{3}}/{v3:[0-9]{3}}" ),
@@ -430,6 +420,7 @@ func TestPath(t *testing.T) {
430
420
for _ , test := range tests {
431
421
testRoute (t , test )
432
422
testTemplate (t , test )
423
+ testUseEscapedRoute (t , test )
433
424
}
434
425
}
435
426
@@ -507,6 +498,7 @@ func TestPathPrefix(t *testing.T) {
507
498
for _ , test := range tests {
508
499
testRoute (t , test )
509
500
testTemplate (t , test )
501
+ testUseEscapedRoute (t , test )
510
502
}
511
503
}
512
504
@@ -583,6 +575,7 @@ func TestHostPath(t *testing.T) {
583
575
for _ , test := range tests {
584
576
testRoute (t , test )
585
577
testTemplate (t , test )
578
+ testUseEscapedRoute (t , test )
586
579
}
587
580
}
588
581
@@ -909,6 +902,7 @@ func TestQueries(t *testing.T) {
909
902
for _ , test := range tests {
910
903
testRoute (t , test )
911
904
testTemplate (t , test )
905
+ testUseEscapedRoute (t , test )
912
906
}
913
907
}
914
908
@@ -1068,6 +1062,7 @@ func TestSubRouter(t *testing.T) {
1068
1062
for _ , test := range tests {
1069
1063
testRoute (t , test )
1070
1064
testTemplate (t , test )
1065
+ testUseEscapedRoute (t , test )
1071
1066
}
1072
1067
}
1073
1068
@@ -1161,6 +1156,40 @@ func TestStrictSlash(t *testing.T) {
1161
1156
},
1162
1157
}
1163
1158
1159
+ for _ , test := range tests {
1160
+ testRoute (t , test )
1161
+ testTemplate (t , test )
1162
+ testUseEscapedRoute (t , test )
1163
+ }
1164
+ }
1165
+
1166
+ func TestUseEncodedPath (t * testing.T ) {
1167
+ r := NewRouter ()
1168
+ r .UseEncodedPath ()
1169
+
1170
+ tests := []routeTest {
1171
+ {
1172
+ title : "Router with useEncodedPath, URL with encoded slash does match" ,
1173
+ route : r .NewRoute ().Path ("/v1/{v1}/v2" ),
1174
+ request : newRequest ("GET" , "http://localhost/v1/1%2F2/v2" ),
1175
+ vars : map [string ]string {"v1" : "1%2F2" },
1176
+ host : "" ,
1177
+ path : "/v1/1%2F2/v2" ,
1178
+ pathTemplate : `/v1/{v1}/v2` ,
1179
+ shouldMatch : true ,
1180
+ },
1181
+ {
1182
+ title : "Router with useEncodedPath, URL with encoded slash doesn't match" ,
1183
+ route : r .NewRoute ().Path ("/v1/1/2/v2" ),
1184
+ request : newRequest ("GET" , "http://localhost/v1/1%2F2/v2" ),
1185
+ vars : map [string ]string {"v1" : "1%2F2" },
1186
+ host : "" ,
1187
+ path : "/v1/1%2F2/v2" ,
1188
+ pathTemplate : `/v1/1/2/v2` ,
1189
+ shouldMatch : false ,
1190
+ },
1191
+ }
1192
+
1164
1193
for _ , test := range tests {
1165
1194
testRoute (t , test )
1166
1195
testTemplate (t , test )
@@ -1375,6 +1404,11 @@ func testRoute(t *testing.T, test routeTest) {
1375
1404
}
1376
1405
}
1377
1406
1407
+ func testUseEscapedRoute (t * testing.T , test routeTest ) {
1408
+ test .route .useEncodedPath = true
1409
+ testRoute (t , test )
1410
+ }
1411
+
1378
1412
func testTemplate (t * testing.T , test routeTest ) {
1379
1413
route := test .route
1380
1414
pathTemplate := test .pathTemplate
0 commit comments