-
-
Notifications
You must be signed in to change notification settings - Fork 980
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
Fix regex/param matching for paths with dots #813
Conversation
FYI, we can't run the CI, since this PR is still in draft. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Please rebase the PR to kick off CI
if segmentlen == -1 { | ||
segmentlen = len(xsearch) | ||
} else { | ||
segmentlen += 1 // just keep the old code working |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just keep the old code working
What does this mean? I don't follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this branch doesn't work well for the bellow snippet (unlike master branch).
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"github.com/go-chi/chi/v5"
)
func main() {
mux := chi.NewMux()
mux.Get("/{param:[^.]+}.{ext:.+}", func(w http.ResponseWriter, r *http.Request) {
param := chi.URLParam(r, "param")
ext := chi.URLParam(r, "ext")
_, _ = fmt.Fprintf(w, "param=%s, ext=%s", param, ext)
})
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/param.json", nil)
mux.ServeHTTP(rec, req)
fmt.Printf("code: %d, body: %s\n", rec.Code, rec.Body)
rec = httptest.NewRecorder()
req = httptest.NewRequest(http.MethodGet, "/param.tar.gz", nil)
mux.ServeHTTP(rec, req)
fmt.Printf("code: %d, body: %s\n", rec.Code, rec.Body)
}
I'm going to close this PR. I think r.Get("/{param:[^.]+}.{ext:.+}", ...
is a sufficient workaround.
Thanks for your work on this!
Fixes #758
based on #811