Skip to content

Commit 399c852

Browse files
ivanmatmatiGopher Bot
authored andcommitted
BUG/MINOR: fix regsub backreference in RequestRedirect ReplacePrefixMatch
HAProxy's regsub converter does not support backreferences in the substitution string. The generated expression %[path,regsub(^/old(/.*)?\$,/new\1)] caused a parse error: 'missing arguments (got 1/2)' because \1 is not a valid substitution in regsub. regsub replaces only the matched portion of the string and leaves the remainder intact, so no capture group is needed. Use the simpler form: %[path,regsub(^/old,/new)]
1 parent 370e8f6 commit 399c852

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

.aspell.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,6 @@ allowed:
109109
- httpfilters
110110
- allowlist
111111
- inttest
112+
- regsub
113+
- backreference
114+
- backreferences

k8s/gate/haproxy/filters/http_filters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func requestRedirectRules(f *gatewayv1.HTTPRequestRedirectFilter, matchPrefix st
384384
}
385385
escapedPrefix := regexEscapePath(matchPrefix)
386386
return models.HTTPRequestRules{
387-
redirect(fmt.Sprintf("%s%%[path,regsub(^%s(/.*)?$,%s\\1)]",
387+
redirect(fmt.Sprintf("%s%%[path,regsub(^%s,%s)]",
388388
pfx, escapedPrefix, replacement), "", ""),
389389
}
390390
}

0 commit comments

Comments
 (0)