Skip to content

Conversation

@salonichf5
Copy link
Contributor

Proposed changes

Write a clear and concise description that helps reviewers understand the purpose and impact of your changes. Use the
following format:

Problem: Users had trouble specifying the PCRE style regex expressions when migrating from nginx-ingress

Solution: Use regexp2 to validate regular expression which is Perl5 library and ensure it is PCRE and RE2 friendly to avoid any breaking changes.

Testing: Manual testing, unit tests.

Testing with regular expressions from customer issues

cafe-route.yaml

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: coffee
spec:
  parentRefs:
  - name: cafe
  hostnames:
  - cafe.example.com
  rules:
  - matches:
    - path:
        type: RegularExpression
        value: /(service\/(?!private/).*) --> does not allow /service/private
    backendRefs:
    - name: coffee-v1-svc
      port: 80
  - matches:
    - path:
        type: RegularExpression
        value: /rest/.*/V1/order/get/.*
      headers:
      - name: headerRegex
        type: RegularExpression
        value: "header-[a-z]{1}"
    - path:
        type: RegularExpression
        value: /rest/.*/V1/order/get/.*
      queryParams:
      - name: queryRegex
        type: RegularExpression
        value: "query-[a-z]{1}"
    backendRefs:
    - name: coffee-v3-svc
      port: 80

config

server {
    listen 80;
    listen [::]:80;

    server_name cafe.example.com;
       location ~ /(service\/(?!private/).*) {
        proxy_pass http://default_coffee-v1-svc_80$request_uri;
    }
    location ~ /rest/.*/V1/order/get/.* {
       set $match_key 1_1;
        js_content httpmatches.redirect;
    }
    location /_ngf-internal-rule1-route0 {
        internal;
        proxy_pass http://default_coffee-v3-svc_80$request_uri;
    }
    location /_ngf-internal-rule1-route1 {
        internal;
        proxy_pass http://default_coffee-v3-svc_80$request_uri;
    }
}
curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/service/private/hello
Handling connection for 8080
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

sa.choudhary@N9939CQ4P0 nginx-gateway-fabric % curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/service/private/server
Handling connection for 8080
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/service/coffee
Handling connection for 8080
Server address: 10.244.0.149:8080
Server name: coffee-v1-55fcb4c6b7-k6qld
Date: 11/Dec/2025:20:54:47 +0000
URI: /service/coffee
Request ID: d69503b10ac9d5e37568b8efa5d5b4fd

regex with query params and headers regex -- multiple matches

sa.choudhary@N9939CQ4P0 nginx-gateway-fabric % curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/rest/example/V1/order/get/customer\?queryRegex\=query-a
Handling connection for 8080
Server address: 10.244.0.151:8080
Server name: coffee-v3-5f7d4f6f47-vzpb8
Date: 11/Dec/2025:21:02:00 +0000
URI: /rest/example/V1/order/get/customer?queryRegex=query-a
Request ID: 1800b9049d08da54ec8c7cbcd316308d


sa.choudhary@N9939CQ4P0 nginx-gateway-fabric % curl --resolve cafe.example.com:$GW_PORT:$GW_IP -H "headerRegex: header-a" http://cafe.example.com:$GW_PORT/rest/example/V1/order/get/lists
Handling connection for 8080
Server address: 10.244.0.151:8080
Server name: coffee-v3-5f7d4f6f47-vzpb8
Date: 11/Dec/2025:21:02:50 +0000
URI: /rest/example/V1/order/get/lists
Request ID: f65e504c759ba42b5fda75dfab1cc853

Please focus on (optional): If you any specific areas where you would like reviewers to focus their attention or provide
specific feedback, add them here.

Closes #4409

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

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.

Updated validation for pathType RegularExpression to support PCRE-style patterns while remaining RE2-friendly, improving compatibility with other projects.

@salonichf5 salonichf5 requested a review from a team as a code owner December 11, 2025 21:04
@salonichf5 salonichf5 requested a review from Copilot December 11, 2025 21:04
@github-actions github-actions bot added enhancement New feature or request dependencies Pull requests that update a dependency file labels Dec 11, 2025
Copy link

Copilot AI left a 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 updates the regular expression validation for pathType: RegularExpression to support PCRE-style patterns while maintaining RE2 compatibility, addressing user migration issues from nginx-ingress. The implementation switches from Go's standard regexp package to the regexp2 library, which provides Perl5-compatible regex support with RE2 compatibility mode.

Key Changes:

  • Replaced restrictive RE2-only validation with regexp2-based validation supporting PCRE patterns
  • Removed explicit bans on backreferences, lookarounds, and unescaped $ characters
  • Expanded test coverage to include PCRE-style patterns like named groups, lookaheads, and backreferences

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
go.mod Added github.com/dlclark/regexp2 v1.11.5 dependency for Perl5-compatible regex support
internal/controller/nginx/config/validation/common.go Replaced regexp.Regexp with regexp2.Regexp, simplified validation logic by removing RE2-specific restrictions, updated documentation
internal/controller/nginx/config/validation/common_test.go Expanded valid test cases to include PCRE patterns (lookaheads, backreferences, variable-width lookbehinds), removed previously-forbidden patterns from invalid test cases, added inline comments explaining test cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Dec 11, 2025

Codecov Report

❌ Patch coverage is 30.76923% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.05%. Comparing base (932f9aa) to head (a793dfb).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ernal/controller/nginx/config/validation/common.go 30.76% 3 Missing and 6 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4450   +/-   ##
=======================================
  Coverage   86.05%   86.05%           
=======================================
  Files         132      132           
  Lines       14389    14382    -7     
  Branches       35       35           
=======================================
- Hits        12383    12377    -6     
+ Misses       1795     1791    -4     
- Partials      211      214    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@salonichf5 salonichf5 force-pushed the feat/update-regex-pkg branch from c591e11 to 440ae67 Compare December 11, 2025 21:11
@salonichf5 salonichf5 requested a review from Copilot December 11, 2025 21:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@bjee19 bjee19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job

@salonichf5 salonichf5 enabled auto-merge (squash) December 11, 2025 21:43
@salonichf5 salonichf5 merged commit f536ed9 into main Dec 11, 2025
59 of 61 checks passed
@salonichf5 salonichf5 deleted the feat/update-regex-pkg branch December 11, 2025 22:09
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in NGINX Gateway Fabric Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request release-notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Path type RegularExpression matcher

4 participants