Skip to content

Commit

Permalink
strip last path parameter in router's find method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TeddyDD committed Mar 13, 2022
1 parent 0f62afb commit d20d1e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit d20d1e0

Please sign in to comment.