-
Notifications
You must be signed in to change notification settings - Fork 136
Add regex for path matching #3874
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
Conversation
Hi @fabian4!
Thanks for opening this pull request!
Be sure to check out our Contributing Guidelines while you wait for someone on the team to review this.
2202934
to
72227ea
Compare
Hey @fabian4, thanks a lot for your contribution to NGINX Gateway Fabric!
I noticed there are still some parts left in this PR—were you looking for initial feedback before continuing development, or are you planning to submit this in parts?
Hi @salonichf5, thanks a lot for the comment! I kept this PR as a draft since there are still some parts I’d like to finish up. In the meantime, getting some early feedback would be super helpful — that way I can adjust things early and make sure I’m heading in the right direction. Really appreciate your input!
72227ea
to
54135b5
Compare
c76e809
to
63c06fe
Compare
Hi @salonichf5, thanks a lot for the comment! I kept this PR as a draft since there are still some parts I’d like to finish up. In the meantime, getting some early feedback would be super helpful — that way I can adjust things early and make sure I’m heading in the right direction. Really appreciate your input!
For sure, we will get some eyes on it. Thank you again for the contribution.
@fabian4 We'll be sure to review this soon!
In the meantime, I ran the pipeline and there are some linting/unit test errors. Also, please be sure to follow this guide for formatting your main commit message and PR description. And please update the release note section the PR description as well, so we can include a notein our CHANGELOG when this ultimately gets released.
194ac10
to
ff24ee1
Compare
@Copilot
Copilot
AI
left a comment
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.
Pull Request Overview
This PR adds regex support for path matching in NGINX Gateway Fabric, extending the existing exact and prefix path matching capabilities. It introduces a new PathTypeRegularExpression
type and implements the necessary validation and configuration logic to support regex-based routing.
Key changes:
- Adds validation infrastructure for regex path patterns with RE2 compatibility
- Updates dataplane configuration to handle regex path types
- Modifies NGINX config generation to create regex location blocks with
~
prefix
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
internal/controller/state/validation/validator.go | Adds new interface method for regex path validation |
internal/controller/state/validation/validationfakes/fake_httpfields_validator.go | Updates test fake with new regex validation method |
internal/controller/state/graph/httproute_test.go | Updates test expectations to accept regex paths |
internal/controller/state/graph/httproute.go | Implements regex path validation in route matching logic |
internal/controller/state/dataplane/types.go | Adds PathTypeRegularExpression constant |
internal/controller/state/dataplane/convert_test.go | Updates test to handle regex path conversion |
internal/controller/state/dataplane/convert.go | Adds regex path type conversion |
internal/controller/nginx/config/validation/http_njs_match_test.go | Removes obsolete path validation test |
internal/controller/nginx/config/validation/http_njs_match.go | Removes path validation method moved to common |
internal/controller/nginx/config/validation/http_filters.go | Adds new path validation methods |
internal/controller/nginx/config/validation/common_test.go | Adds comprehensive regex path validation tests |
internal/controller/nginx/config/validation/common.go | Implements regex path validation with RE2 constraints |
internal/controller/nginx/config/servers_test.go | Updates test expectations for new path formatting |
internal/controller/nginx/config/servers.go | Implements regex location generation and path handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
ff24ee1
to
7f70c31
Compare
https://github.com/nginx/nginx-gateway-fabric/actions/runs/17919926662/job/50987553809?pr=3874
https://github.com/nginx/nginx-gateway-fabric/actions/runs/17919926622/job/50987553763?pr=3874
BTW I can't figure why above test are failing since I can't get any thing like that when I run unit test and lint on my env.
It says the github.com/nginx/agent/v3@v3.3.1
package sum mismatch and the go lint location is empty
. I don't think I have touched the related code, So still confused about the reason here.
@fabian4 Yeah I saw similar issues on my fork recently as well, not sure what's happening there. We'll investigate.
@fabian I just had the first successful run for my fork test PR, so hopefully the pipeline issues should resolve for you now.
I'll get on to testing your PR once we can run the linter and tests in the pipeline.
Problem: As regex path matching is missing support for NGF. Solution: Add support for regex path matching, only allow a full path rewrite/redirect after the regex path match. Testing: Add additional unit test case for regex path match.
7f70c31
to
895c15c
Compare
Testing done on the branch Error expected cases:
Case 1: Drops its if starts with
Case 2: unescaped $
Case 3: Very long pattern
|
Testing done on the branch Checking functionality that Regex works as expected
|
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.
should we panic here like we do for other cases @ciarams87 ?
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.
i guess its fine, this is how we have handled it in the past so should be good
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.
I think your first instinct was correct actually - this should be a panic. Now this function silently returns an invalid location path instead of at least returning the original path as a fallback. This is a programmer error (all path types should be handled), not a runtime error from user input (which is validated earlier), so panic() is appropriate and consistent.
We need to also validate preexisting behaviour for URLRewrite, Redirect and other filters.
@fabian4 Thank you for your patience. We are currently testing Regex thoroughly—both on its own and in combination with our other filters.
We’ll consolidate all findings and provide you with a complete review of the changes required, so they can be addressed together.
I really appreciate your contribution. From my initial round of testing, everything looks good overall, with only a few exceptions that we’d like to discuss as a team to decide whether we want to allow them or not.
Uh oh!
There was an error while loading. Please reload this page.
Proposed changes
Problem: Add regex for path matching
external (regex path match without any head/method/queryparams condition)
Closes #3110
Checklist
Before creating a PR, run through this checklist and mark each as complete.
Release notes
If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.