-
-
Notifications
You must be signed in to change notification settings - Fork 988
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
Routing bug with empty path component #609
Comments
Having the same issue with subroutes:
Second match is not expected. |
One note about empty route segments is that some browser (like Chrome) will automatically remove them during URL normalization. It's still probably correct to consider this a bug, but in practice having empty route segments should be discouraged due to the fact that the user may not be able to navigate to them. |
This bug is caused by not setting xn to nil in time when ntype is equal to ntRegexp and traversing the child nodes. I want to fix this bug, please assign this issue to me. |
Having the same issue with subroutes: import (
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
)
func dummy(w http.ResponseWriter, r *http.Request) {}
func main() {
r := chi.NewRouter()
r.Route(`/{handle:[a-zA-Z\d._-]+}`, func(r chi.Router) {
r.Get(`/`, dummy)
// ...
})
http.ListenAndServe(":3333", r)
} With this example, |
any progress for #609 (comment) @pkieltyka |
Surprising this bug still exists many years later. The work around I'm looking into using right now is: // ...
r.Route("//", func(r chi.Router) {
// blackhole *//* requests
})
r.Route("/key:[a-z]+"), func(r chi.Router) {
// ...
})
// ... chi will reply with Alternatively you can just use a middleware that ensures the parameter matches your regex manually. |
Hi, I found a surprising (to me) edge case regarding routes with empty path components:
This prints
The route matched the URL.
even though there was clearly no match for the regular expression. My understanding of the semantics of a regex filter is that the route will match if and only if the regex filter matches the path component, but that's not what seems to be happening here.I'd be curious if this is behaving as it should, and if so, if there's a good alternative to filtering out empty path components, since requirning a match on
.+
doesn't work.Thank you!
P. S. I think this a bug, since omitting the trailing slash from both the pattern and URL should not change the behavior but doing so makes the route no longer match (click to expand):
The text was updated successfully, but these errors were encountered: