mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 19:53:19 +00:00
🚀 improve routing behavior
This commit is contained in:
parent
582b10a6d4
commit
2283fd2756
6
path.go
6
path.go
@ -256,7 +256,11 @@ func findParamLen(s string, segments []routeSegment, currIndex int) int {
|
||||
}
|
||||
// get the length to the next constant part
|
||||
if false == nextSeg.IsParam {
|
||||
if constPosition := strings.Index(s, nextSeg.Const); constPosition != -1 {
|
||||
searchString := nextSeg.Const
|
||||
if len(searchString) > 1 {
|
||||
searchString = utils.TrimRight(nextSeg.Const, slashDelimiter)
|
||||
}
|
||||
if constPosition := strings.Index(s, searchString); constPosition != -1 {
|
||||
return constPosition
|
||||
}
|
||||
}
|
||||
|
39
path_test.go
39
path_test.go
@ -128,12 +128,11 @@ func Test_Path_matchParams(t *testing.T) {
|
||||
{url: "/foobar", params: []string{""}, match: true},
|
||||
{url: "/", params: []string{""}, match: false},
|
||||
})
|
||||
// TODO: fix it
|
||||
//testCase("/a*cde*g/", []testparams{
|
||||
// {url: "/abbbcdefffg", params: []string{"bbb", "fff"}, match: true},
|
||||
// {url: "/acdeg", params: []string{"", ""}, match: true},
|
||||
// {url: "/", params: nil, match: false},
|
||||
//})
|
||||
testCase("/a*cde*g/", []testparams{
|
||||
{url: "/abbbcdefffg", params: []string{"bbb", "fff"}, match: true},
|
||||
{url: "/acdeg", params: []string{"", ""}, match: true},
|
||||
{url: "/", params: nil, match: false},
|
||||
})
|
||||
testCase("/*v1*/proxy", []testparams{
|
||||
{url: "/customer/v1/cart/proxy", params: []string{"customer/", "/cart"}, match: true},
|
||||
{url: "/v1/proxy", params: []string{"", ""}, match: true},
|
||||
@ -162,7 +161,7 @@ func Test_Path_matchParams(t *testing.T) {
|
||||
testCase("/api/v1/:param/abc/*", []testparams{
|
||||
{url: "/api/v1/well/abc/wildcard", params: []string{"well", "wildcard"}, match: true},
|
||||
{url: "/api/v1/well/abc/", params: []string{"well", ""}, match: true},
|
||||
{url: "/api/v1/well/abc", params: nil, match: false},
|
||||
{url: "/api/v1/well/abc", params: []string{"well", ""}, match: true},
|
||||
{url: "/api/v1/well/ttt", params: nil, match: false},
|
||||
})
|
||||
testCase("/api/:day/:month?/:year?", []testparams{
|
||||
@ -235,19 +234,19 @@ func Test_Path_matchParams(t *testing.T) {
|
||||
{url: "xyz/", params: nil, match: false},
|
||||
})
|
||||
// TODO: fix this
|
||||
//testCase("/api/*/:param?", []testparams{
|
||||
// {url: "/api/", params: []string{"", ""}, match: true},
|
||||
// {url: "/api/joker", params: []string{"joker", ""}, match: true},
|
||||
// {url: "/api/joker/batman", params: []string{"joker", "batman"}, match: true},
|
||||
// {url: "/api/joker//batman", params: []string{"joker//batman", "batman"}, match: true},
|
||||
// {url: "/api/joker/batman/robin", params: []string{"joker/batman", "robin"}, match: true},
|
||||
// {url: "/api/joker/batman/robin/1", params: []string{"joker/batman/robin", "1"}, match: true},
|
||||
// {url: "/api/joker/batman/robin/1/", params: []string{"joker/batman/robin/1", ""}, match: true},
|
||||
// {url: "/api/joker-batman/robin/1", params: []string{"joker-batman/robin", "1"}, match: true},
|
||||
// {url: "/api/joker-batman-robin/1", params: []string{"joker-batman-robin", "1"}, match: true},
|
||||
// {url: "/api/joker-batman-robin-1", params: []string{"joker-batman-robin-1", ""}, match: true},
|
||||
// {url: "/api", params: []string{"", ""}, match: true},
|
||||
//})
|
||||
testCase("/api/*/:param?", []testparams{
|
||||
{url: "/api/", params: []string{"", ""}, match: true},
|
||||
{url: "/api/joker", params: []string{"joker", ""}, match: true},
|
||||
{url: "/api/joker/batman", params: []string{"joker", "batman"}, match: true},
|
||||
//{url: "/api/joker//batman", params: []string{"joker//batman", "batman"}, match: true},
|
||||
//{url: "/api/joker/batman/robin", params: []string{"joker/batman", "robin"}, match: true},
|
||||
//{url: "/api/joker/batman/robin/1", params: []string{"joker/batman/robin", "1"}, match: true},
|
||||
//{url: "/api/joker/batman/robin/1/", params: []string{"joker/batman/robin/1", ""}, match: true},
|
||||
//{url: "/api/joker-batman/robin/1", params: []string{"joker-batman/robin", "1"}, match: true},
|
||||
//{url: "/api/joker-batman-robin/1", params: []string{"joker-batman-robin", "1"}, match: true},
|
||||
//{url: "/api/joker-batman-robin-1", params: []string{"joker-batman-robin-1", ""}, match: true},
|
||||
{url: "/api", params: []string{"", ""}, match: true},
|
||||
})
|
||||
//testCase("/api/*/:param", []testparams{
|
||||
// {url: "/api/test/abc", params: []string{"test", "abc"}, match: true},
|
||||
// {url: "/api/joker/batman", params: []string{"joker", "batman"}, match: true},
|
||||
|
Loading…
x
Reference in New Issue
Block a user