mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-17 15:37:29 +08:00
22
tree_test.go
22
tree_test.go
@ -192,6 +192,7 @@ func TestTreeWildcard(t *testing.T) {
|
||||
"/get/abc/123abg/:param",
|
||||
"/get/abc/123abf/:param",
|
||||
"/get/abc/123abfff/:param",
|
||||
"/get/abc/escaped_colon/test\\:param",
|
||||
}
|
||||
for _, route := range routes {
|
||||
tree.addRoute(route, fakeHandler(route))
|
||||
@ -315,6 +316,7 @@ func TestTreeWildcard(t *testing.T) {
|
||||
{"/get/abc/123abg/test", false, "/get/abc/123abg/:param", Params{Param{Key: "param", Value: "test"}}},
|
||||
{"/get/abc/123abf/testss", false, "/get/abc/123abf/:param", Params{Param{Key: "param", Value: "testss"}}},
|
||||
{"/get/abc/123abfff/te", false, "/get/abc/123abfff/:param", Params{Param{Key: "param", Value: "te"}}},
|
||||
{"/get/abc/escaped_colon/test\\:param", false, "/get/abc/escaped_colon/test\\:param", nil},
|
||||
})
|
||||
|
||||
checkPriorities(t, tree)
|
||||
@ -419,6 +421,9 @@ func TestTreeWildcardConflict(t *testing.T) {
|
||||
{"/id/:id", false},
|
||||
{"/static/*file", false},
|
||||
{"/static/", true},
|
||||
{"/escape/test\\:d1", false},
|
||||
{"/escape/test\\:d2", false},
|
||||
{"/escape/test:param", false},
|
||||
}
|
||||
testRoutes(t, routes)
|
||||
}
|
||||
@ -971,3 +976,20 @@ func TestTreeWildcardConflictEx(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeInvalidEscape(t *testing.T) {
|
||||
routes := map[string]bool{
|
||||
"/r1/r": true,
|
||||
"/r2/:r": true,
|
||||
"/r3/\\:r": true,
|
||||
}
|
||||
tree := &node{}
|
||||
for route, valid := range routes {
|
||||
recv := catchPanic(func() {
|
||||
tree.addRoute(route, fakeHandler(route))
|
||||
})
|
||||
if recv == nil != valid {
|
||||
t.Fatalf("%s should be %t but got %v", route, valid, recv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user