mirror of https://github.com/gofiber/fiber.git
* Add possibility for parameters before custom verb
FIX for "🤗 How to get path param before a custom verb? #1931"
* try to stabilize the tests
pull/1987/head
parent
ad89ba4e1c
commit
ff1e0109a3
|
@ -124,7 +124,7 @@ func Test_Proxy_Balancer_WithTlsConfig(t *testing.T) {
|
||||||
|
|
||||||
// go test -run Test_Proxy_Forward_WithTlsConfig_To_Http
|
// go test -run Test_Proxy_Forward_WithTlsConfig_To_Http
|
||||||
func Test_Proxy_Forward_WithTlsConfig_To_Http(t *testing.T) {
|
func Test_Proxy_Forward_WithTlsConfig_To_Http(t *testing.T) {
|
||||||
t.Parallel()
|
//t.Parallel()
|
||||||
|
|
||||||
_, targetAddr := createProxyTestServer(func(c *fiber.Ctx) error {
|
_, targetAddr := createProxyTestServer(func(c *fiber.Ctx) error {
|
||||||
return c.SendString("hello from target")
|
return c.SendString("hello from target")
|
||||||
|
|
2
path.go
2
path.go
|
@ -58,7 +58,7 @@ var (
|
||||||
// list of chars for the parameter recognising
|
// list of chars for the parameter recognising
|
||||||
parameterStartChars = []byte{wildcardParam, plusParam, paramStarterChar}
|
parameterStartChars = []byte{wildcardParam, plusParam, paramStarterChar}
|
||||||
// list of chars of delimiters and the starting parameter name char
|
// list of chars of delimiters and the starting parameter name char
|
||||||
parameterDelimiterChars = append([]byte{paramStarterChar}, routeDelimiter...)
|
parameterDelimiterChars = append([]byte{paramStarterChar, escapeChar}, routeDelimiter...)
|
||||||
// list of chars to find the end of a parameter
|
// list of chars to find the end of a parameter
|
||||||
parameterEndChars = append([]byte{optionalParam}, parameterDelimiterChars...)
|
parameterEndChars = append([]byte{optionalParam}, parameterDelimiterChars...)
|
||||||
)
|
)
|
||||||
|
|
15
path_test.go
15
path_test.go
|
@ -47,6 +47,17 @@ func Test_Path_parseRoute(t *testing.T) {
|
||||||
},
|
},
|
||||||
params: nil,
|
params: nil,
|
||||||
}, rp)
|
}, rp)
|
||||||
|
|
||||||
|
rp = parseRoute("/v1/some/resource/:name\\:customVerb")
|
||||||
|
utils.AssertEqual(t, routeParser{
|
||||||
|
segs: []*routeSegment{
|
||||||
|
{Const: "/v1/some/resource/", Length: 18},
|
||||||
|
{IsParam: true, ParamName: "name", ComparePart: ":customVerb", PartCount: 1},
|
||||||
|
{Const: ":customVerb", Length: 11, IsLast: true},
|
||||||
|
},
|
||||||
|
params: []string{"name"},
|
||||||
|
}, rp)
|
||||||
|
|
||||||
// heavy test with escaped charaters
|
// heavy test with escaped charaters
|
||||||
rp = parseRoute("/v1/some/resource/name\\\\:customVerb?\\?/:param/*")
|
rp = parseRoute("/v1/some/resource/name\\\\:customVerb?\\?/:param/*")
|
||||||
utils.AssertEqual(t, routeParser{
|
utils.AssertEqual(t, routeParser{
|
||||||
|
@ -170,6 +181,10 @@ func Test_Path_matchParams(t *testing.T) {
|
||||||
{url: "/v1/some/resource/name:customVerb", params: nil, match: true},
|
{url: "/v1/some/resource/name:customVerb", params: nil, match: true},
|
||||||
{url: "/v1/some/resource/name:test", params: nil, match: false},
|
{url: "/v1/some/resource/name:test", params: nil, match: false},
|
||||||
})
|
})
|
||||||
|
testCase("/v1/some/resource/:name\\:customVerb", []testparams{
|
||||||
|
{url: "/v1/some/resource/test:customVerb", params: []string{"test"}, match: true},
|
||||||
|
{url: "/v1/some/resource/test:test", params: nil, match: false},
|
||||||
|
})
|
||||||
testCase("/v1/some/resource/name\\\\:customVerb?\\?/:param/*", []testparams{
|
testCase("/v1/some/resource/name\\\\:customVerb?\\?/:param/*", []testparams{
|
||||||
{url: "/v1/some/resource/name:customVerb??/test/optionalWildCard/character", params: []string{"test", "optionalWildCard/character"}, match: true},
|
{url: "/v1/some/resource/name:customVerb??/test/optionalWildCard/character", params: []string{"test", "optionalWildCard/character"}, match: true},
|
||||||
{url: "/v1/some/resource/name:customVerb??/test", params: []string{"test", ""}, match: true},
|
{url: "/v1/some/resource/name:customVerb??/test", params: []string{"test", ""}, match: true},
|
||||||
|
|
Loading…
Reference in New Issue