Closed
Description
Router1 "/get/test/abc/" Router2 "/get/:param/abc/"
I tests these two routers with some requests:
/get/test/abc/ -> Router1
/get/xyz/abc/ -> Router2
/get/tt/abc/ -> 404(Expect Router2)
So, if there are some param starts with the prefix 't' in this example, it will not get the right router.
Originally posted by @Tevic in #2663 (comment)
Metadata
Metadata
Assignees
Labels
No labels
Activity
rw-access commentedon Apr 9, 2021
I don't have the ability to self-assign this, but feel free to assign me.
I've got an idea for a fix.
g1eny0ung commentedon Apr 22, 2021
@rw-access I'm also facing this problem, here are the example routes I defined:
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:
Since the node indices will build as
asf
to make a fast deep search. When accessing the route like/archives
, the above code will jump into/api
route group to find the matching route, then it failed (return 404).Before #2663, the above code wrapped with an if condition
if !n.wildChild
so it can be executed normally without any other side effect.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:
I’m not sure if there are other things to pay attention to. Hope to get your feedback.
appleboy commentedon Apr 28, 2021
@rw-access Can you take a look at the PR #2706?