Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

6543
Copy link

@6543 6543 commented Apr 11, 2023

Fixes #758

based on #811

@VojtechVitek
Copy link
Contributor

FYI, we can't run the CI, since this PR is still in draft.

@VojtechVitek VojtechVitek marked this pull request as ready for review September 25, 2024 11:03
@VojtechVitek VojtechVitek added v5 v6 and removed v5 labels Sep 25, 2024
@VojtechVitek VojtechVitek changed the title Add tests for #758 Fix regex/param matching for paths with dots Sep 25, 2024
Copy link
Contributor

@VojtechVitek VojtechVitek left a 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
Copy link
Contributor

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.

@VojtechVitek VojtechVitek removed the v6 label Sep 25, 2024
Copy link
Contributor

@VojtechVitek VojtechVitek left a 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!

@6543 6543 deleted the add-tests-for-758 branch September 25, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regex param doesn't match dots
2 participants