Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching prefixes among multiple routers causes 404 #2696

Closed
muety opened this issue Apr 19, 2021 · 2 comments · Fixed by #2706
Closed

Matching prefixes among multiple routers causes 404 #2696

muety opened this issue Apr 19, 2021 · 2 comments · Fixed by #2706
Labels

Comments

@muety
Copy link

muety commented Apr 19, 2021

I'm not particularly experienced with Gin, so I might well have gotten something wrong here. However, the following behavior appears strange to me. Consider this small example:

package main

import (
	"net/http"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.New()

	// useless because of https://github.com/golang/go/blob/a7e16abb22f1b249d2691b32a5d20206282898f2/src/net/http/fs.go#L587, but anyway ...
	r.StaticFile("/index.html", "./public/index.html")
	r.StaticFile("/robots.txt", "./public/robots.txt")
	r.GET("/:id", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{"status": "success"})
	})
	
	r.Run()
}

Expected vs. actual behavior

$ curl http://localhost:8080/aaaa # -> shall return 200, does return 200
$ curl http://localhost:8080/iaaa # -> shall return 200, does return 404
$ curl http://localhost:8080/raaa # -> shall return 200, does return 404

If I remove the robots.txt handler, the third request will be 200 instead. Looks like if my request's path has a prefix, which is also a prefix of one of the other handlers, things get messed up.

Might be a duplicate of #2682.

@muety
Copy link
Author

muety commented Apr 19, 2021

In version 1.6.3 the above code yields a panic instead, which, I suppose, relates to the change made in #2663.

panic: wildcard segment ':id' conflicts with existing children in path '/:id'

@appleboy
Copy link
Member

Please upgrade to v1.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants