From d20d1e04626473d53f6c60577c12be97a21011a4 Mon Sep 17 00:00:00 2001 From: Daniel Lewan Date: Sat, 12 Mar 2022 20:55:53 +0100 Subject: [PATCH] strip last path parameter in router's find method To support Titan router must strip path parameters from last segment of the path in find method. Otherwise paths like /foo;size=1 won't match declared path /foo in router. Path segment parameters are described in RFC 3986, section 3.3. --- router.go | 5 +++++ router_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/router.go b/router.go index 1a021a5..cf7f022 100644 --- a/router.go +++ b/router.go @@ -227,6 +227,11 @@ func (n *node) findChildByKind(t kind) *node { // find lookup a handler registered for path. It also parses URL for path // parameters and load them into context. func (r *router) find(path string, c Context) { + i := strings.Index(path, ";") + if i != -1 { + path = path[0:i] + } + ctx := c.(*context) ctx.path = path cn := r.tree // Current node as root diff --git a/router_test.go b/router_test.go index 3478da8..f150a53 100644 --- a/router_test.go +++ b/router_test.go @@ -1210,6 +1210,14 @@ func TestRouterParam1466(t *testing.T) { is.Equal("sharewithme", c.Param("username")) is.Equal("self", c.Param("type")) + r.find("/users/sharewithme/uploads/self;mime=text/plain;size=24", c) + is.Equal("sharewithme", c.Param("username")) + is.Equal("self", c.Param("type")) + + r.find("/users/sharewithme/uploads/self?foo=1", c) + is.Equal("sharewithme", c.Param("username")) + is.Equal("self?foo=1", c.Param("type")) + c = g.newContext(nil, nil, "", nil).(*context) r.find("/users/ajitem/uploads/self", c) is.Equal("ajitem", c.Param("username"))