-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
[Bug] Mixed params and exact paths can cause a 404 #2682
Comments
I don't have the ability to self-assign this, but feel free to assign me. |
@rw-access I'm also facing this problem, here are the example routes I defined: r.GET("/", xxx)
r.GET("/:foo", xxx)
r.Group("/api", xxx)
r.GET("/static/*any", xxx)
r.GET("/favicon.ico", xxx) For the realworld project needed, I try to solve this problem. After debugging, I found that it's related to https://github.com/gin-gonic/gin/pull/2663/files#diff-050830ac4334170e8d335e1b95519052a3461c5b57a4ca38a0531e35a8f3d388R410: // Try all the non-wildcard children first by matching the indices
idxc := path[0]
for i, c := range []byte(n.indices) {
if c == idxc {
n = n.children[i]
continue walk
}
} Since the node indices will build as Before #2663, the above code wrapped with an if condition I wanted to propose a PR for repair, but I think it’s best to discuss how to do it. Seems to solve this problem, I think it's needed to add an extra condition like if children have a :param node after c == idxc?Here is an example of linking the above code: // Try all the non-wildcard children first by matching the indices
idxc := path[0]
for i, c := range []byte(n.indices) {
if c == idxc {
childWillWalkTo := n.children[i]
if strings.Split(childWillWalkTo.path, "/")[0] != strings.Split(path, "/")[0] && strings.HasPrefix(n.children[len(n.children)-1].path, ":") {
// "api" != "archives" && :foo has :
continue
} else {
n = childWillWalkTo
continue walk
}
}
} I’m not sure if there are other things to pay attention to. Hope to get your feedback. |
@rw-access Can you take a look at the PR #2706? |
Originally posted by @Tevic in #2663 (comment)
The text was updated successfully, but these errors were encountered: