Skip to content

Commit

Permalink
Add possibility for parameters before custom verb
Browse files Browse the repository at this point in the history
FIX for "🤗 How to get path param before a custom verb? #1931"
  • Loading branch information
ReneWerner87 committed Jul 26, 2022
1 parent ad89ba4 commit 614b760
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion path.go
Expand Up @@ -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...)
)
Expand Down
15 changes: 15 additions & 0 deletions path_test.go
Expand Up @@ -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{
Expand Down Expand Up @@ -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},
Expand Down

1 comment on commit 614b760

@ReneWerner87
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 614b760 Previous: f8272d0 Ratio
Benchmark_AcquireCtx 1119 ns/op 1568 B/op 5 allocs/op 38.17 ns/op 0 B/op 0 allocs/op 29.32
Benchmark_Ctx_Protocol 15.94 ns/op 0 B/op 0 allocs/op 2.772 ns/op 0 B/op 0 allocs/op 5.75

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.