From: Stefan Fritsch Date: Sat, 30 Jan 2010 11:20:53 +0000 (+0000) Subject: Make ap_pregsub(), used by AliasMatch and friends, use the same syntax X-Git-Tag: 2.3.6~539 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b74009049025b3098ce8c49939d56887eac6d04;p=apache Make ap_pregsub(), used by AliasMatch and friends, use the same syntax for regex backreferences as mod_rewrite and mod_include: Remove the use of '&' as an alias for '$0' and allow to escape any character with a backslash. Document the use of $0. PR: 48351 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@904765 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 42cf2d4bdf..05e8c39d7c 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,11 @@ Changes with Apache 2.3.5 optimization in the case of no request body. PR 48359 [Jake Scott, William Rowe, Ruediger Pluem] + *) Make ap_pregsub(), used by AliasMatch and friends, use the same syntax + for regex backreferences as mod_rewrite and mod_include: Remove the use + of '&' as an alias for '$0' and allow to escape any character with a + backslash. PR 48351. [Stefan Fritsch] + *) Turn static function get_server_name_for_url() into public ap_get_server_name_for_url() and use it where appropriate. This fixes mod_rewrite generating invalid URLs for redirects to IPv6 @@ -36,7 +41,7 @@ Changes with Apache 2.3.5 *) mod_cache: Do an exact match of the keys defined by CacheIgnoreURLSessionIdentifiers against the querystring instead of - a partial match. PR 48401.i + a partial match. PR 48401. [Dodou Wang , Ruediger Pluem] *) mod_proxy_balancer: Fix crash in balancer-manager. [Rainer Jung] diff --git a/docs/manual/glossary.html.en b/docs/manual/glossary.html.en index ff75c7ebfd..7e31099975 100644 --- a/docs/manual/glossary.html.en +++ b/docs/manual/glossary.html.en @@ -362,9 +362,17 @@ expressions are useful in Apache because they let you apply certain attributes against collections of files or resources in very flexible ways - for example, all .gif and .jpg files under any "images" directory could - be written as "/images/.*(jpg|gif)$". Apache uses Perl - Compatible Regular Expressions provided by the PCRE library. You can find more documentation - about PCRE's regular expression syntax at that site, or at + be written as "/images/.*(jpg|gif)$". In places where + regular expressions are used to replace strings, the special variables + $1 ... $9 contain backreferences to the grouped parts (in parentheses) of + the matched expression. The special variable $0 contains a backerference + to the whole matched expression. To write a literal dollar sign in a + replacement string, it can be escaped with a backslash. Historically, the + variable & could be used as alias for $0 in some places. This is no + longer possible since version 2.3.5. Apache uses Perl Compatible Regular + Expressions provided by the PCRE + library. You can find more documentation about PCRE's regular expression + syntax at that site, or at Wikipedia. diff --git a/docs/manual/glossary.xml b/docs/manual/glossary.xml index d6d842a84f..53a7f38826 100644 --- a/docs/manual/glossary.xml +++ b/docs/manual/glossary.xml @@ -380,10 +380,17 @@ expressions are useful in Apache because they let you apply certain attributes against collections of files or resources in very flexible ways - for example, all .gif and .jpg files under any "images" directory could - be written as "/images/.*(jpg|gif)$". Apache uses Perl - Compatible Regular Expressions provided by the PCRE library. You can find more documentation - about PCRE's regular expression syntax at that site, or at + be written as "/images/.*(jpg|gif)$". In places where + regular expressions are used to replace strings, the special variables + $1 ... $9 contain backreferences to the grouped parts (in parentheses) of + the matched expression. The special variable $0 contains a backerference + to the whole matched expression. To write a literal dollar sign in a + replacement string, it can be escaped with a backslash. Historically, the + variable & could be used as alias for $0 in some places. This is no + longer possible since version 2.3.5. Apache uses Perl Compatible Regular + Expressions provided by the PCRE + library. You can find more documentation about PCRE's regular expression + syntax at that site, or at Wikipedia. diff --git a/docs/manual/mod/mod_include.html.en b/docs/manual/mod/mod_include.html.en index a9ff1e16ff..e54c4b8f0d 100644 --- a/docs/manual/mod/mod_include.html.en +++ b/docs/manual/mod/mod_include.html.en @@ -558,7 +558,8 @@

If you are matching positive (= or ==), you can capture grouped parts of the regular expression. The captured parts are stored in the special variables $1 .. - $9.

+ $9. The whole string matched by the regular expression is + stored in the special variable $0

Example

<!--#if expr="$QUERY_STRING = /^sid=([a-zA-Z0-9]+)/" -->
diff --git a/docs/manual/mod/mod_include.xml b/docs/manual/mod/mod_include.xml index 332e9fbd8c..e08204ccd3 100644 --- a/docs/manual/mod/mod_include.xml +++ b/docs/manual/mod/mod_include.xml @@ -547,7 +547,8 @@

If you are matching positive (= or ==), you can capture grouped parts of the regular expression. The captured parts are stored in the special variables $1 .. - $9.

+ $9. The whole string matched by the regular expression is + stored in the special variable $0

Example <!--#if expr="$QUERY_STRING = /^sid=([a-zA-Z0-9]+)/" -->
diff --git a/docs/manual/mod/mod_rewrite.html.en b/docs/manual/mod/mod_rewrite.html.en index 9472a05e5b..916e564a9d 100644 --- a/docs/manual/mod/mod_rewrite.html.en +++ b/docs/manual/mod/mod_rewrite.html.en @@ -132,18 +132,20 @@ RewriteRule ^index\.html$ newsite.html
  • RewriteRule backreferences: These are backreferences of the form $N - (0 <= N <= 9), which provide access to the grouped + (0 <= N <= 9). $1 to $9 provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current - set of RewriteCond conditions. + set of RewriteCond conditions. $0 provides + access to the whole string matched by that pattern.
  • RewriteCond backreferences: These are backreferences of the form %N - (1 <= N <= 9), which provide access to the grouped + (0 <= N <= 9). %1 to %9 provide access to the grouped parts (again, in parentheses) of the pattern, from the last matched RewriteCond in the current set - of conditions. + of conditions. %0 provides access to the whole string matched by + that pattern.
  • RewriteMap expansions: These are diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index f5b9fa44ca..78d67ea1df 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -542,18 +542,20 @@ RewriteRule ^index\.html$ newsite.html
  • RewriteRule backreferences: These are backreferences of the form $N - (0 <= N <= 9), which provide access to the grouped + (0 <= N <= 9). $1 to $9 provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current - set of RewriteCond conditions. + set of RewriteCond conditions. $0 provides + access to the whole string matched by that pattern.
  • RewriteCond backreferences: These are backreferences of the form %N - (1 <= N <= 9), which provide access to the grouped + (0 <= N <= 9). %1 to %9 provide access to the grouped parts (again, in parentheses) of the pattern, from the last matched RewriteCond in the current set - of conditions. + of conditions. %0 provides access to the whole string matched by + that pattern.
  • RewriteMap expansions: These are diff --git a/server/util.c b/server/util.c index 729c754baa..e645235de5 100644 --- a/server/util.c +++ b/server/util.c @@ -376,15 +376,13 @@ AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, len = 0; while ((c = *src++) != '\0') { - if (c == '&') - no = 0; - else if (c == '$' && apr_isdigit(*src)) + if (c == '$' && apr_isdigit(*src)) no = *src++ - '0'; else no = 10; if (no > 9) { /* Ordinary character. */ - if (c == '\\' && (*src == '$' || *src == '&')) + if (c == '\\' && *src) c = *src++; len++; }