@ -335,16 +335,6 @@ func TestPath(t *testing.T) {
@@ -335,16 +335,6 @@ func TestPath(t *testing.T) {
pathTemplate : ` /111/ { v1:[0-9] { 3}}/333 ` ,
shouldMatch : false ,
} ,
{
title : "Path route, URL with encoded slash does match" ,
route : new ( Route ) . Path ( "/v1/{v1}/v2" ) ,
request : newRequest ( "GET" , "http://localhost/v1/1%2F2/v2" ) ,
vars : map [ string ] string { "v1" : "1%2F2" } ,
host : "" ,
path : "/v1/1%2F2/v2" ,
pathTemplate : ` /v1/ { v1}/v2 ` ,
shouldMatch : true ,
} ,
{
title : "Path route with multiple patterns, match" ,
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,6 +420,7 @@ func TestPath(t *testing.T) {
for _ , test := range tests {
testRoute ( t , test )
testTemplate ( t , test )
testUseEscapedRoute ( t , test )
}
}
@ -507,6 +498,7 @@ func TestPathPrefix(t *testing.T) {
@@ -507,6 +498,7 @@ func TestPathPrefix(t *testing.T) {
for _ , test := range tests {
testRoute ( t , test )
testTemplate ( t , test )
testUseEscapedRoute ( t , test )
}
}
@ -583,6 +575,7 @@ func TestHostPath(t *testing.T) {
@@ -583,6 +575,7 @@ func TestHostPath(t *testing.T) {
for _ , test := range tests {
testRoute ( t , test )
testTemplate ( t , test )
testUseEscapedRoute ( t , test )
}
}
@ -909,6 +902,7 @@ func TestQueries(t *testing.T) {
@@ -909,6 +902,7 @@ func TestQueries(t *testing.T) {
for _ , test := range tests {
testRoute ( t , test )
testTemplate ( t , test )
testUseEscapedRoute ( t , test )
}
}
@ -1068,6 +1062,7 @@ func TestSubRouter(t *testing.T) {
@@ -1068,6 +1062,7 @@ func TestSubRouter(t *testing.T) {
for _ , test := range tests {
testRoute ( t , test )
testTemplate ( t , test )
testUseEscapedRoute ( t , test )
}
}
@ -1161,6 +1156,40 @@ func TestStrictSlash(t *testing.T) {
@@ -1161,6 +1156,40 @@ func TestStrictSlash(t *testing.T) {
} ,
}
for _ , test := range tests {
testRoute ( t , test )
testTemplate ( t , test )
testUseEscapedRoute ( t , test )
}
}
func TestUseEncodedPath ( t * testing . T ) {
r := NewRouter ( )
r . UseEncodedPath ( )
tests := [ ] routeTest {
{
title : "Router with useEncodedPath, URL with encoded slash does match" ,
route : r . NewRoute ( ) . Path ( "/v1/{v1}/v2" ) ,
request : newRequest ( "GET" , "http://localhost/v1/1%2F2/v2" ) ,
vars : map [ string ] string { "v1" : "1%2F2" } ,
host : "" ,
path : "/v1/1%2F2/v2" ,
pathTemplate : ` /v1/ { v1}/v2 ` ,
shouldMatch : true ,
} ,
{
title : "Router with useEncodedPath, URL with encoded slash doesn't match" ,
route : r . NewRoute ( ) . Path ( "/v1/1/2/v2" ) ,
request : newRequest ( "GET" , "http://localhost/v1/1%2F2/v2" ) ,
vars : map [ string ] string { "v1" : "1%2F2" } ,
host : "" ,
path : "/v1/1%2F2/v2" ,
pathTemplate : ` /v1/1/2/v2 ` ,
shouldMatch : false ,
} ,
}
for _ , test := range tests {
testRoute ( t , test )
testTemplate ( t , test )
@ -1375,6 +1404,11 @@ func testRoute(t *testing.T, test routeTest) {
@@ -1375,6 +1404,11 @@ func testRoute(t *testing.T, test routeTest) {
}
}
func testUseEscapedRoute ( t * testing . T , test routeTest ) {
test . route . useEncodedPath = true
testRoute ( t , test )
}
func testTemplate ( t * testing . T , test routeTest ) {
route := test . route
pathTemplate := test . pathTemplate