-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
regexp route nested wrongly -> no routing #411
Comments
Apparently, if you make a different regex, but it matches the other, it returns a 404. I had this example: r.Get("/one/{firstId:[a-z0-9-]+}/{secondId:[a-z0-9-]+}/type.json", handler)
r.Get("/one/{firstId:[a-z0-9-_]+}/{secondId:[a-z0-9-_]+}.json", secondHandler} I could access the first path, but not the second. |
Same problem here! 😞 |
The same happen in here. In this example, get routes works but delete returns 405 (not allowed): r.Route("/one", func(r chi.Router) {
r.Get("/{dns:[a-z-0-9_]+}", getHandler)
r.Get("/{dns:[a-z-0-9_]+}/info", infoHandle)
...
r.Delete("/{id:[0-9]+}", deleteHandler)
}) if I remove the first get route, then delete returns 404 (route not found), like Felipe said: r.Route("/one", func(r chi.Router) {
// r.Get("/{dns:[a-z-0-9_]+}", getHandler)
r.Get("/{dns:[a-z-0-9_]+}/info", infoHandle)
...
r.Delete("/{id:[0-9]+}", deleteHandler)
}) And in this, all routes works: r.Route("/one", func(r chi.Router) {
r.Get("/{dns:[a-z-0-9_]+}", getHandler)
r.Get("/{dns:[a-z-0-9_]+}/info", infoHandle)
...
})
r.Delete("/one/{id:[0-9]+}", deleteHandler) 🤷♂️ |
I think that’s because the Route struct is composed of one pattern string and a map of handlers. |
Try putting /*/ before each request pattern |
hey all, I've found the bug for this issue. The issue is in the func TestMuxRegexp4(t *testing.T) {
r := NewRouter()
r.Get("/one/{firstId:[a-z0-9-]+}/{secondId:[a-z]+}/first", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("first"))
})
r.Get("/one/{firstId:[a-z0-9-_]+}/{secondId:[0-9]+}/second", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("second"))
})
ts := httptest.NewServer(r)
defer ts.Close()
if _, body := testRequest(t, ts, "GET", "/one/hello/peter/first", nil); body != "first" {
t.Fatalf(body)
}
if _, body := testRequest(t, ts, "GET", "/one/hithere/123/second", nil); body != "second" {
t.Fatalf(body)
}
} here is a test case that should pass but in fact is not. The reason for it is that the just FYI in case someone wants to take a stab at it |
thanks to @Jahaja 's PR, this is now solved in master |
I've been scratching my head for the past day where the chi wouldn't route the request properly. Here are the registered routes.
The text was updated successfully, but these errors were encountered: