]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Some Perl/Python regex fluff changes - correct the test here.
authorJim Jagielski <jim@apache.org>
Fri, 5 Jun 2026 20:07:27 +0000 (20:07 +0000)
committerJim Jagielski <jim@apache.org>
Fri, 5 Jun 2026 20:07:27 +0000 (20:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1935050 13f79535-47bb-0310-9956-ffa450edef68

test/pytest_suite/tests/t/modules/test_substitute.py

index 44d1c326b3edbc5223f17f890be3cbaef011f532..810a6005c423721394076f46eedb354e075131fe 100644 (file)
@@ -110,7 +110,11 @@ def _httpd_rule_to_python(content, rule):
         return re.sub(pattern, lambda m: repl, content, flags=flags)
 
     # Map HTTPD $0 (whole match) and $N backrefs to python \g<0> / \N.
-    # Also handle perl '&' meaning whole match (used in s/<body>/&/).
+    # NOTE: '&' is NOT a whole-match metachar here. mod_substitute uses $0/$N
+    # for backrefs only, and the Perl reference test computes its expectation by
+    # running the rule through perl's own s/// (substitute.t:73-80), where a bare
+    # '&' in the replacement is a literal '&' ($& is the match var, not &). So
+    # s/<body>/&/ yields a literal 'x&x' -- which is what the server returns.
     def to_py_repl(s):
         out = []
         i = 0
@@ -140,7 +144,9 @@ def _httpd_rule_to_python(content, rule):
                 i += 2
                 continue
             if c == "&":
-                out.append("\\g<0>")
+                # literal '&' (see note above), not whole-match. '&' has no
+                # special meaning in an re.sub replacement, so emit it as-is.
+                out.append("&")
                 i += 1
                 continue
             out.append(c)