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

Wildcard matching with regex pattern is not correctly parsing the path values #932

Open
shettyh opened this issue Jul 11, 2024 · 1 comment · May be fixed by #933
Open

Wildcard matching with regex pattern is not correctly parsing the path values #932

shettyh opened this issue Jul 11, 2024 · 1 comment · May be fixed by #933
Labels

Comments

@shettyh
Copy link

shettyh commented Jul 11, 2024

Combining two related issues here. Please let me know if that is not fine, will create separate issues.

Issue 1: Path values are not correct

Endpoint: /payments/{id: [0-9]{4}}*

Request Path: /payments/4765_payID/status

Expected Path Keys and Values: { "id" : "4765", "*" : "_payID/status" }

Actual Path Keys and Values: `{ "id": "", "*": "4765_payID/status" }

I am sure there are other ways to register the same route like /payments/{id: [0-9]{4}}{local_wildcard}/* to handle the above cases but this doesn't allow /payments/1234_payID work around is to define two routes in that case. We are facing this issue as we are migrating from another router ( lua based ) to Chi and we want to keep the routes backward compatible. Does it make sense to support this usecase ? If so then i can take a initial look at this and raise a PR for the same.

Issue 2: Extension to the Issue 1, Wildcard endpoint is ignored

  • Endpoint 1 : /payments/{id: [0-9]{4}}*
  • Endpoint 2: /payments/{id: [0-9]{4}}/status

Request Path: /payments/4765_payID/not_status

Expected Status Code : 200 ( Path Matched )

Actual Status Code: 404 ( No route matched )

When there are multiple childs along with wildcard, it follows the path without wildcard in this case. I was thinking why not add * also in the sort function here to push the wildcards to the last ( tried locally, works fine). Please share your thoughts, i can raise the PR for the same

@shettyh shettyh linked a pull request Jul 11, 2024 that will close this issue
@shettyh
Copy link
Author

shettyh commented Jul 11, 2024

Added PR for the fix here https:/go-chi/chi/pull/933/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants