Skip to content

Commit

Permalink
fix path substring incorrectly matching to route (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: Arash KORDI <arash.kordi@vestiairecollective.com>
  • Loading branch information
hawell and Arash KORDI committed Jan 24, 2023
1 parent 670b7ce commit b5e63c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion radix/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (n *node) split(i int) {

func (n *node) findEndIndexAndValues(path string) (int, []string) {
index := n.paramRegex.FindStringSubmatchIndex(path)
if len(index) == 0 {
if len(index) == 0 || index[0] != 0 {
return -1, nil
}

Expand Down
4 changes: 4 additions & 0 deletions radix/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func TestTreeAddAndGet(t *testing.T) {
"/hello/test",
"/hello/tooth",
"/hello/{name}",
"/regex/{c1:big_alt|alt|small_alt}/{rest:*}",
"/regex/{path:*}",
}

for _, route := range routes {
Expand All @@ -142,6 +144,8 @@ func TestTreeAddAndGet(t *testing.T) {
{"/hello/testastretta", false, "/hello/{name}", map[string]interface{}{"name": "testastretta"}},
{"/hello/tes", false, "/hello/{name}", map[string]interface{}{"name": "tes"}},
{"/hello/test/bye", true, "", nil},
{"/regex/more_alt/hello", false, "/regex/{path:*}", map[string]interface{}{"path": "more_alt/hello"}},
{"/regex/small_alt/hello", false, "/regex/{c1:big_alt|alt|small_alt}/{rest:*}", map[string]interface{}{"c1": "small_alt", "rest": "hello"}},
})
}

Expand Down

0 comments on commit b5e63c0

Please sign in to comment.