From 6603de9e5fc80270cc79d7b7b40ca5312c7c499c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Efe=20=C3=87etin?= Date: Wed, 7 Sep 2022 17:44:56 +0300 Subject: [PATCH 1/2] :bug: bug: fix constraints when to use multiple params --- path.go | 14 +++---------- path_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/path.go b/path.go index 27f09f5f9e..927a97aaca 100644 --- a/path.go +++ b/path.go @@ -362,23 +362,15 @@ func findLastCharsetPosition(search string, charset []byte) int { // findNextCharsetPositionConstraint search the next char position from the charset // unlike findNextCharsetPosition, it takes care of constraint start-end chars to parse route pattern func findNextCharsetPositionConstraint(search string, charset []byte) int { + constraintStart := findNextNonEscapedCharsetPosition(search, parameterConstraintStartChars) + constraintEnd := findNextNonEscapedCharsetPosition(search, parameterConstraintEndChars) nextPosition := -1 - constraintStart := -1 - constraintEnd := -1 for _, char := range charset { pos := strings.IndexByte(search, char) - if char == paramConstraintStart { - constraintStart = pos - } - - if char == paramConstraintEnd { - constraintEnd = pos - } - if pos != -1 && (pos < nextPosition || nextPosition == -1) { - if pos > constraintStart && pos < constraintEnd { + if (pos > constraintStart && pos > constraintEnd) || (pos < constraintStart && pos < constraintEnd) { nextPosition = pos } } diff --git a/path_test.go b/path_test.go index ca02ea2b15..b25816c401 100644 --- a/path_test.go +++ b/path_test.go @@ -568,6 +568,35 @@ func Test_Path_matchParams(t *testing.T) { {url: "/api/v1/1200", params: []string{"1200"}, match: true}, {url: "/api/v1/true", params: []string{"true"}, match: false}, }) + testCase("/api/v1/:lang/videos/:page", []testparams{ + {url: "/api/v1/try/videos/200", params: []string{"try", "200"}, match: false}, + {url: "/api/v1/tr/videos/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/tr/videos/100", params: []string{"tr", "100"}, match: true}, + {url: "/api/v1/e/videos/10", params: []string{"tr", "200"}, match: false}, + }) + testCase("/api/v1/:lang/:page", []testparams{ + {url: "/api/v1/try/200", params: []string{"try", "200"}, match: false}, + {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, + {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + }) + testCase("/api/v1/:lang/:page", []testparams{ + {url: "/api/v1/try/200", params: []string{"try", "200"}, match: true}, + {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, + {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + }) + testCase("/api/v1/:lang/:page", []testparams{ + {url: "/api/v1/try/200", params: []string{"try", "200"}, match: false}, + {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: true}, + {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, + {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + }) + testCase("/api/v1/:date/:regex", []testparams{ + {url: "/api/v1/2005-11-01/a", params: []string{"2005-11-01", "a"}, match: false}, + {url: "/api/v1/2005-1101/paach", params: []string{"2005-1101", "a"}, match: false}, + {url: "/api/v1/2005-11-01/peach", params: []string{"2005-11-01", "peach"}, match: true}, + }) } func Test_Utils_GetTrimmedParam(t *testing.T) { @@ -793,4 +822,33 @@ func Benchmark_Path_matchParams(t *testing.B) { {url: "/api/v1/1200", params: []string{"1200"}, match: true}, {url: "/api/v1/true", params: []string{"true"}, match: false}, }) + benchCase("/api/v1/:lang/videos/:page", []testparams{ + {url: "/api/v1/try/videos/200", params: []string{"try", "200"}, match: false}, + {url: "/api/v1/tr/videos/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/tr/videos/100", params: []string{"tr", "100"}, match: true}, + {url: "/api/v1/e/videos/10", params: []string{"tr", "200"}, match: false}, + }) + benchCase("/api/v1/:lang/:page", []testparams{ + {url: "/api/v1/try/200", params: []string{"try", "200"}, match: false}, + {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, + {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + }) + benchCase("/api/v1/:lang/:page", []testparams{ + {url: "/api/v1/try/200", params: []string{"try", "200"}, match: true}, + {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, + {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + }) + benchCase("/api/v1/:lang/:page", []testparams{ + {url: "/api/v1/try/200", params: []string{"try", "200"}, match: false}, + {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: true}, + {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, + {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + }) + benchCase("/api/v1/:date/:regex", []testparams{ + {url: "/api/v1/2005-11-01/a", params: []string{"2005-11-01", "a"}, match: false}, + {url: "/api/v1/2005-1101/paach", params: []string{"2005-1101", "a"}, match: false}, + {url: "/api/v1/2005-11-01/peach", params: []string{"2005-11-01", "peach"}, match: true}, + }) } From c9e35783cc78dccf1d2d51edccb82288265a7d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Werner?= Date: Thu, 8 Sep 2022 07:17:16 +0200 Subject: [PATCH 2/2] test case route matching remove the parameters for negative routing matches, as they are unnecessary and should not be considered there --- path_test.go | 256 +++++++++++++++++++++++++-------------------------- 1 file changed, 128 insertions(+), 128 deletions(-) diff --git a/path_test.go b/path_test.go index b25816c401..5e89e1a875 100644 --- a/path_test.go +++ b/path_test.go @@ -432,128 +432,128 @@ func Test_Path_matchParams(t *testing.T) { {url: "/api/:test", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, {url: "/api/v1/8728382", params: []string{"8728382"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/true", params: []string{"true"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, {url: "/api/v1/8728382", params: []string{"8728382"}, match: true}, {url: "/api/v1/8728382.5", params: []string{"8728382.5"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ {url: "/api/v1/entity", params: []string{"entity"}, match: true}, - {url: "/api/v1/#!?", params: []string{"#!?"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/#!?", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/f0fa66cc-d22e-445b-866d-1d76e776371d", params: []string{"f0fa66cc-d22e-445b-866d-1d76e776371d"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ {url: "/api/v1/entity", params: []string{"entity"}, match: true}, - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, {url: "/api/v1/8728382", params: []string{"8728382"}, match: true}, - {url: "/api/v1/123", params: []string{"123"}, match: false}, + {url: "/api/v1/123", params: nil, match: false}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, {url: "/api/v1/ent", params: []string{"ent"}, match: true}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, - {url: "/api/v1/123", params: []string{"123"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, + {url: "/api/v1/123", params: nil, match: false}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/e", params: []string{"e"}, match: false}, + {url: "/api/v1/e", params: nil, match: false}, {url: "/api/v1/en", params: []string{"en"}, match: true}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/e", params: []string{"e"}, match: false}, + {url: "/api/v1/e", params: nil, match: false}, {url: "/api/v1/en", params: []string{"en"}, match: true}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, - {url: "/api/v1/1", params: []string{"1"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, + {url: "/api/v1/1", params: nil, match: false}, {url: "/api/v1/5", params: []string{"5"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, {url: "/api/v1/1", params: []string{"1"}, match: true}, {url: "/api/v1/5", params: []string{"5"}, match: true}, - {url: "/api/v1/15", params: []string{"15"}, match: false}, + {url: "/api/v1/15", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, {url: "/api/v1/9", params: []string{"9"}, match: true}, {url: "/api/v1/5", params: []string{"5"}, match: true}, - {url: "/api/v1/15", params: []string{"15"}, match: false}, + {url: "/api/v1/15", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/2005-11-01", params: []string{"2005-11-01"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, - {url: "/api/v1/15", params: []string{"15"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, + {url: "/api/v1/15", params: nil, match: false}, {url: "/api/v1/peach", params: []string{"peach"}, match: true}, - {url: "/api/v1/p34ch", params: []string{"p34ch"}, match: false}, + {url: "/api/v1/p34ch", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, - {url: "/api/v1/15", params: []string{"15"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, + {url: "/api/v1/15", params: nil, match: false}, {url: "/api/v1/2022-08-27", params: []string{"2022-08-27"}, match: true}, - {url: "/api/v1/2022/08-27", params: []string{"p34ch"}, match: false}, + {url: "/api/v1/2022/08-27", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, {url: "/api/v1/8728382", params: []string{"8728382"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/87283827683", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/87283827683", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/87283827683", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/87283827683", params: nil, match: false}, {url: "/api/v1/25", params: []string{"25"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) testCase("/api/v1/:param", []testparams{ {url: "/api/v1/entity", params: []string{"entity"}, match: true}, @@ -562,39 +562,39 @@ func Test_Path_matchParams(t *testing.T) { {url: "/api/v1/true", params: []string{"true"}, match: true}, }) testCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/87283827683", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/87283827683", params: nil, match: false}, {url: "/api/v1/25", params: []string{"25"}, match: true}, {url: "/api/v1/1200", params: []string{"1200"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) testCase("/api/v1/:lang/videos/:page", []testparams{ - {url: "/api/v1/try/videos/200", params: []string{"try", "200"}, match: false}, - {url: "/api/v1/tr/videos/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/try/videos/200", params: nil, match: false}, + {url: "/api/v1/tr/videos/1800", params: nil, match: false}, {url: "/api/v1/tr/videos/100", params: []string{"tr", "100"}, match: true}, - {url: "/api/v1/e/videos/10", params: []string{"tr", "200"}, match: false}, + {url: "/api/v1/e/videos/10", params: nil, match: false}, }) testCase("/api/v1/:lang/:page", []testparams{ - {url: "/api/v1/try/200", params: []string{"try", "200"}, match: false}, - {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/try/200", params: nil, match: false}, + {url: "/api/v1/tr/1800", params: nil, match: false}, {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, - {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + {url: "/api/v1/e/10", params: nil, match: false}, }) testCase("/api/v1/:lang/:page", []testparams{ {url: "/api/v1/try/200", params: []string{"try", "200"}, match: true}, - {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/tr/1800", params: nil, match: false}, {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, - {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + {url: "/api/v1/e/10", params: nil, match: false}, }) testCase("/api/v1/:lang/:page", []testparams{ - {url: "/api/v1/try/200", params: []string{"try", "200"}, match: false}, + {url: "/api/v1/try/200", params: nil, match: false}, {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: true}, {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, - {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + {url: "/api/v1/e/10", params: nil, match: false}, }) testCase("/api/v1/:date/:regex", []testparams{ - {url: "/api/v1/2005-11-01/a", params: []string{"2005-11-01", "a"}, match: false}, - {url: "/api/v1/2005-1101/paach", params: []string{"2005-1101", "a"}, match: false}, + {url: "/api/v1/2005-11-01/a", params: nil, match: false}, + {url: "/api/v1/2005-1101/paach", params: nil, match: false}, {url: "/api/v1/2005-11-01/peach", params: []string{"2005-11-01", "peach"}, match: true}, }) } @@ -686,128 +686,128 @@ func Benchmark_Path_matchParams(t *testing.B) { {url: "/api/v1/", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, {url: "/api/v1/8728382", params: []string{"8728382"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/true", params: []string{"true"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, {url: "/api/v1/8728382", params: []string{"8728382"}, match: true}, {url: "/api/v1/8728382.5", params: []string{"8728382.5"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ {url: "/api/v1/entity", params: []string{"entity"}, match: true}, - {url: "/api/v1/#!?", params: []string{"#!?"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/#!?", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/f0fa66cc-d22e-445b-866d-1d76e776371d", params: []string{"f0fa66cc-d22e-445b-866d-1d76e776371d"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ {url: "/api/v1/entity", params: []string{"entity"}, match: true}, - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, {url: "/api/v1/8728382", params: []string{"8728382"}, match: true}, - {url: "/api/v1/123", params: []string{"123"}, match: false}, + {url: "/api/v1/123", params: nil, match: false}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, {url: "/api/v1/ent", params: []string{"ent"}, match: true}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, - {url: "/api/v1/123", params: []string{"123"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, + {url: "/api/v1/123", params: nil, match: false}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/e", params: []string{"e"}, match: false}, + {url: "/api/v1/e", params: nil, match: false}, {url: "/api/v1/en", params: []string{"en"}, match: true}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/e", params: []string{"e"}, match: false}, + {url: "/api/v1/e", params: nil, match: false}, {url: "/api/v1/en", params: []string{"en"}, match: true}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, {url: "/api/v1/12345", params: []string{"12345"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, - {url: "/api/v1/1", params: []string{"1"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, + {url: "/api/v1/1", params: nil, match: false}, {url: "/api/v1/5", params: []string{"5"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, {url: "/api/v1/1", params: []string{"1"}, match: true}, {url: "/api/v1/5", params: []string{"5"}, match: true}, - {url: "/api/v1/15", params: []string{"15"}, match: false}, + {url: "/api/v1/15", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, {url: "/api/v1/9", params: []string{"9"}, match: true}, {url: "/api/v1/5", params: []string{"5"}, match: true}, - {url: "/api/v1/15", params: []string{"15"}, match: false}, + {url: "/api/v1/15", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/2005-11-01", params: []string{"2005-11-01"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, - {url: "/api/v1/15", params: []string{"15"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, + {url: "/api/v1/15", params: nil, match: false}, {url: "/api/v1/peach", params: []string{"peach"}, match: true}, - {url: "/api/v1/p34ch", params: []string{"p34ch"}, match: false}, + {url: "/api/v1/p34ch", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/ent", params: []string{"ent"}, match: false}, - {url: "/api/v1/15", params: []string{"15"}, match: false}, + {url: "/api/v1/ent", params: nil, match: false}, + {url: "/api/v1/15", params: nil, match: false}, {url: "/api/v1/2022-08-27", params: []string{"2022-08-27"}, match: true}, - {url: "/api/v1/2022/08-27", params: []string{"p34ch"}, match: false}, + {url: "/api/v1/2022/08-27", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, {url: "/api/v1/8728382", params: []string{"8728382"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/8728382", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/8728382", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/87283827683", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/87283827683", params: nil, match: false}, {url: "/api/v1/123", params: []string{"123"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/87283827683", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/87283827683", params: nil, match: false}, {url: "/api/v1/25", params: []string{"25"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) benchCase("/api/v1/:param", []testparams{ {url: "/api/v1/entity", params: []string{"entity"}, match: true}, @@ -816,39 +816,39 @@ func Benchmark_Path_matchParams(t *testing.B) { {url: "/api/v1/true", params: []string{"true"}, match: true}, }) benchCase("/api/v1/:param", []testparams{ - {url: "/api/v1/entity", params: []string{"entity"}, match: false}, - {url: "/api/v1/87283827683", params: []string{"8728382"}, match: false}, + {url: "/api/v1/entity", params: nil, match: false}, + {url: "/api/v1/87283827683", params: nil, match: false}, {url: "/api/v1/25", params: []string{"25"}, match: true}, {url: "/api/v1/1200", params: []string{"1200"}, match: true}, - {url: "/api/v1/true", params: []string{"true"}, match: false}, + {url: "/api/v1/true", params: nil, match: false}, }) benchCase("/api/v1/:lang/videos/:page", []testparams{ - {url: "/api/v1/try/videos/200", params: []string{"try", "200"}, match: false}, - {url: "/api/v1/tr/videos/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/try/videos/200", params: nil, match: false}, + {url: "/api/v1/tr/videos/1800", params: nil, match: false}, {url: "/api/v1/tr/videos/100", params: []string{"tr", "100"}, match: true}, - {url: "/api/v1/e/videos/10", params: []string{"tr", "200"}, match: false}, + {url: "/api/v1/e/videos/10", params: nil, match: false}, }) benchCase("/api/v1/:lang/:page", []testparams{ - {url: "/api/v1/try/200", params: []string{"try", "200"}, match: false}, - {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/try/200", params: nil, match: false}, + {url: "/api/v1/tr/1800", params: nil, match: false}, {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, - {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + {url: "/api/v1/e/10", params: nil, match: false}, }) benchCase("/api/v1/:lang/:page", []testparams{ {url: "/api/v1/try/200", params: []string{"try", "200"}, match: true}, - {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: false}, + {url: "/api/v1/tr/1800", params: nil, match: false}, {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, - {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + {url: "/api/v1/e/10", params: nil, match: false}, }) benchCase("/api/v1/:lang/:page", []testparams{ - {url: "/api/v1/try/200", params: []string{"try", "200"}, match: false}, + {url: "/api/v1/try/200", params: nil, match: false}, {url: "/api/v1/tr/1800", params: []string{"tr", "1800"}, match: true}, {url: "/api/v1/tr/100", params: []string{"tr", "100"}, match: true}, - {url: "/api/v1/e/10", params: []string{"tr", "200"}, match: false}, + {url: "/api/v1/e/10", params: nil, match: false}, }) benchCase("/api/v1/:date/:regex", []testparams{ - {url: "/api/v1/2005-11-01/a", params: []string{"2005-11-01", "a"}, match: false}, - {url: "/api/v1/2005-1101/paach", params: []string{"2005-1101", "a"}, match: false}, + {url: "/api/v1/2005-11-01/a", params: nil, match: false}, + {url: "/api/v1/2005-1101/paach", params: nil, match: false}, {url: "/api/v1/2005-11-01/peach", params: []string{"2005-11-01", "peach"}, match: true}, }) }