From 614b760c8aba17176cccd4acea5fbd84745cb46f Mon Sep 17 00:00:00 2001 From: wernerr Date: Tue, 26 Jul 2022 20:27:28 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Add=20possibility=20for=20parameters=20befo?= =?UTF-8?q?re=20custom=20verb=20FIX=20for=20"=F0=9F=A4=97=20How=20to=20get?= =?UTF-8?q?=20path=20param=20before=20a=20custom=20verb=3F=20#1931"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- path.go | 2 +- path_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/path.go b/path.go index 2f70c7f742..21a3d6c4d0 100644 --- a/path.go +++ b/path.go @@ -58,7 +58,7 @@ var ( // list of chars for the parameter recognising parameterStartChars = []byte{wildcardParam, plusParam, paramStarterChar} // 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 parameterEndChars = append([]byte{optionalParam}, parameterDelimiterChars...) ) diff --git a/path_test.go b/path_test.go index 246cd58f5d..9a237520dd 100644 --- a/path_test.go +++ b/path_test.go @@ -47,6 +47,17 @@ func Test_Path_parseRoute(t *testing.T) { }, params: nil, }, 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 rp = parseRoute("/v1/some/resource/name\\\\:customVerb?\\?/:param/*") 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: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{ {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}, From 5ce117890ddeea08a445228a8a75919cbf9b9032 Mon Sep 17 00:00:00 2001 From: wernerr Date: Wed, 27 Jul 2022 08:20:44 +0200 Subject: [PATCH 2/2] try to stabilize the tests --- middleware/proxy/proxy_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/proxy/proxy_test.go b/middleware/proxy/proxy_test.go index 4e2215c596..906e54669b 100644 --- a/middleware/proxy/proxy_test.go +++ b/middleware/proxy/proxy_test.go @@ -124,7 +124,7 @@ func Test_Proxy_Balancer_WithTlsConfig(t *testing.T) { // go test -run Test_Proxy_Forward_WithTlsConfig_To_Http func Test_Proxy_Forward_WithTlsConfig_To_Http(t *testing.T) { - t.Parallel() + //t.Parallel() _, targetAddr := createProxyTestServer(func(c *fiber.Ctx) error { return c.SendString("hello from target")