This is an automated email from the ASF dual-hosted git repository.

alinsran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git


The following commit(s) were added to refs/heads/master by this push:
     new 15132023 fix(conformance-test): HTTPRoutePathRewrite (#2597)
15132023 is described below

commit 15132023371821df66489c9ea1d4006789c27e71
Author: AlinsRan <[email protected]>
AuthorDate: Mon Oct 13 14:26:08 2025 +0800

    fix(conformance-test): HTTPRoutePathRewrite (#2597)
---
 Makefile                             |  2 +-
 internal/adc/translator/httproute.go | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 322af687..74207326 100644
--- a/Makefile
+++ b/Makefile
@@ -52,7 +52,7 @@ GO_LDFLAGS ?= "-X=$(VERSYM)=$(VERSION) 
-X=$(GITSHASYM)=$(GITSHA) -X=$(BUILDOSSYM
 # gateway-api
 GATEAY_API_VERSION ?= v1.3.0
 ## 
https://github.com/kubernetes-sigs/gateway-api/blob/v1.3.0/pkg/features/httproute.go
-SUPPORTED_EXTENDED_FEATURES = 
"HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080,HTTPRouteHostRewrite,HTTPRouteQueryParamMatching"
+SUPPORTED_EXTENDED_FEATURES = 
"HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080,HTTPRouteHostRewrite,HTTPRouteQueryParamMatching,HTTPRoutePathRewrite"
 CONFORMANCE_TEST_REPORT_OUTPUT ?= 
$(DIR)/apisix-ingress-controller-conformance-report.yaml
 ## 
https://github.com/kubernetes-sigs/gateway-api/blob/v1.3.0/conformance/utils/suite/profiles.go
 CONFORMANCE_PROFILES ?= GATEWAY-HTTP,GATEWAY-GRPC,GATEWAY-TLS
diff --git a/internal/adc/translator/httproute.go 
b/internal/adc/translator/httproute.go
index 3fc1db98..ebee4a45 100644
--- a/internal/adc/translator/httproute.go
+++ b/internal/adc/translator/httproute.go
@@ -118,14 +118,33 @@ func (t *Translator) 
fillPluginFromURLRewriteFilter(plugins adctypes.Plugins, ur
                                }
                                prefixPaths = append(prefixPaths, 
*match.Path.Value)
                        }
-                       regexPattern := "^(" + strings.Join(prefixPaths, "|") + 
")" + "/(.*)"
+                       if len(prefixPaths) == 0 || 
urlRewrite.Path.ReplacePrefixMatch == nil {
+                               break
+                       }
+                       prefixGroup := "(" + strings.Join(prefixPaths, "|") + 
")"
                        replaceTarget := *urlRewrite.Path.ReplacePrefixMatch
-                       regexTarget := replaceTarget + "/$2"
-
-                       plugin.RewriteTargetRegex = []string{
-                               regexPattern,
-                               regexTarget,
+                       // Handle ReplacePrefixMatch path rewrite
+                       // If replaceTarget == "/", special handling is 
required to avoid
+                       // producing double slashes or empty paths.
+                       var regexPattern, regexTarget string
+                       if replaceTarget == "/" {
+                               // Match either "/prefix" or 
"/prefix/<remainder>"
+                               // Pattern captures the remainder (if any) 
without a leading slash.
+                               // Template reconstructs "/" + remainder, 
resulting in:
+                               //   /prefix/three → /three
+                               //   /prefix       → /
+                               regexPattern = "^" + prefixGroup + "(?:/(.*))?$"
+                               regexTarget = "/" + "$2"
+                       } else {
+                               // Match either "/prefix" or 
"/prefix/<remainder>"
+                               // Pattern captures the remainder (including 
leading slash) as $2.
+                               // Template appends it to replaceTarget:
+                               //   /prefix/one/two → /one/two
+                               //   /prefix/one     → /one
+                               regexPattern = "^" + prefixGroup + "(/.*)?$"
+                               regexTarget = replaceTarget + "$2"
                        }
+                       plugin.RewriteTargetRegex = []string{regexPattern, 
regexTarget}
                }
        }
 }

Reply via email to