Skip to content

Commit 0d976f7

Browse files
committed
Add tests for issue #1739
1 parent c7c792d commit 0d976f7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

router_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,47 @@ func TestRouterMatchAny(t *testing.T) {
750750
assert.Equal(t, "joe", c.Param("*"))
751751
}
752752

753+
// Issue #1739
754+
func TestRouterMatchAnyPrefixIssue(t *testing.T) {
755+
e := New()
756+
r := e.router
757+
758+
// Routes
759+
r.Add(http.MethodGet, "/*", func(c Context) error {
760+
c.Set("path", c.Path())
761+
return nil
762+
})
763+
r.Add(http.MethodGet, "/users/*", func(c Context) error {
764+
c.Set("path", c.Path())
765+
return nil
766+
})
767+
c := e.NewContext(nil, nil).(*context)
768+
r.Find(http.MethodGet, "/", c)
769+
c.handler(c)
770+
assert.Equal(t, "/*", c.Get("path"))
771+
assert.Equal(t, "", c.Param("*"))
772+
773+
r.Find(http.MethodGet, "/users", c)
774+
c.handler(c)
775+
assert.Equal(t, "/*", c.Get("path"))
776+
assert.Equal(t, "users", c.Param("*"))
777+
778+
r.Find(http.MethodGet, "/users/", c)
779+
c.handler(c)
780+
assert.Equal(t, "/users/*", c.Get("path"))
781+
assert.Equal(t, "", c.Param("*"))
782+
783+
r.Find(http.MethodGet, "/users_prefix", c)
784+
c.handler(c)
785+
assert.Equal(t, "/*", c.Get("path"))
786+
assert.Equal(t, "users_prefix", c.Param("*"))
787+
788+
r.Find(http.MethodGet, "/users_prefix/", c)
789+
c.handler(c)
790+
assert.Equal(t, "/*", c.Get("path"))
791+
assert.Equal(t, "users_prefix/", c.Param("*"))
792+
}
793+
753794
// TestRouterMatchAnySlash shall verify finding the best route
754795
// for any routes with trailing slash requests
755796
func TestRouterMatchAnySlash(t *testing.T) {

0 commit comments

Comments
 (0)