1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Fix parameter routes with an extension (/foo/:id.json)

This is a follow-up to #1101. It turns out that that patch is
incomplete, as a similar check also needs to be added in the
`Router.Add()` method.

I don't understand why the test works fine, but when using it in a real
application. For example with this example:

	func main() {
		e := echo.New()
		e.GET("/xxx/:id.json", func(c echo.Context) error {
			return c.String(200, fmt.Sprintf("%#v: names: %#v; vals: %#v",
				c.Path(), c.ParamNames(), c.ParamValues()))
		})
		log.Fatal(e.Start(":8000"))
	}

Gives a 404 on `/xxx/42.json`, and for `/xxx/42` it gives the output:

	/xxx/:id.json": names: []string{"id.json"}; vals: []string{"42"}

It makes sense to add the test there too; I just don't get why the test
cases that I added in ##1101 *does* produce the correct output :-/
This commit is contained in:
Martin Tournoij 2018-04-10 21:17:55 +01:00 committed by Vishal Rana
parent 5b769f91b2
commit cf7b55584d

View File

@ -68,7 +68,7 @@ func (r *Router) Add(method, path string, h HandlerFunc) {
j := i + 1
r.insert(method, path[:i], nil, skind, "", nil)
for ; i < l && path[i] != '/'; i++ {
for ; i < l && path[i] != '/' && path[i] != '.'; i++ {
}
pnames = append(pnames, path[j:i])