]> granicus.if.org Git - apache/commitdiff
Make ap_pregsub(), used by AliasMatch and friends, use the same syntax
authorStefan Fritsch <sf@apache.org>
Sat, 30 Jan 2010 11:20:53 +0000 (11:20 +0000)
committerStefan Fritsch <sf@apache.org>
Sat, 30 Jan 2010 11:20:53 +0000 (11:20 +0000)
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

CHANGES
docs/manual/glossary.html.en
docs/manual/glossary.xml
docs/manual/mod/mod_include.html.en
docs/manual/mod/mod_include.xml
docs/manual/mod/mod_rewrite.html.en
docs/manual/mod/mod_rewrite.xml
server/util.c

diff --git a/CHANGES b/CHANGES
index 42cf2d4bdf290a46ecb40ed886a8d2c79c3b3fb1..05e8c39d7c50ad139ca6cff1e10671f86ca2a26d 100644 (file)
--- 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 <wangdong.08 gmail.com>, Ruediger Pluem]
 
   *) mod_proxy_balancer: Fix crash in balancer-manager. [Rainer Jung]
index ff75c7ebfdd2b62863ecd8928bdb39b50a35934b..7e310999751f074768c99acee956323156549922 100644 (file)
       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 "<code>/images/.*(jpg|gif)$</code>".  Apache uses Perl
-      Compatible Regular Expressions provided by the <a href="http://www.pcre.org/">PCRE</a> library.  You can find more documentation
-      about PCRE's regular expression syntax at that site, or at
+      be written as "<code>/images/.*(jpg|gif)$</code>".  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 &amp; 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 <a href="http://www.pcre.org/">PCRE</a>
+      library.  You can find more documentation about PCRE's regular expression
+      syntax at that site, or at
       <a href="http://en.wikipedia.org/wiki/PCRE">Wikipedia</a>.
     </dd>
 
index d6d842a84f25fb37ee0b1832f41680bb9b2becaa..53a7f388269320b51c7eccf7a5b93256303d9d33 100644 (file)
       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 "<code>/images/.*(jpg|gif)$</code>".  Apache uses Perl
-      Compatible Regular Expressions provided by the <a
-      href="http://www.pcre.org/">PCRE</a> library.  You can find more documentation
-      about PCRE's regular expression syntax at that site, or at
+      be written as "<code>/images/.*(jpg|gif)$</code>".  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 &amp; 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 <a href="http://www.pcre.org/">PCRE</a>
+      library.  You can find more documentation about PCRE's regular expression
+      syntax at that site, or at
       <a href="http://en.wikipedia.org/wiki/PCRE">Wikipedia</a>.
     </dd>
 
index a9ff1e16ff9635108618828fd10e71bd109392ae..e54c4b8f0d78c0fbf56196940c7105fbabc70203 100644 (file)
       <p>If you are matching positive (<code>=</code> or <code>==</code>), you
       can capture grouped parts of the regular expression. The captured parts
       are stored in the special variables <code>$1</code> ..
-      <code>$9</code>.</p>
+      <code>$9</code>. The whole string matched by the regular expression is
+      stored in the special variable <code>$0</code></p>
 
       <div class="example"><h3>Example</h3><p><code>
         &lt;!--#if expr="$QUERY_STRING = /^sid=([a-zA-Z0-9]+)/" --&gt;<br />
index 332e9fbd8c6d754cb2af056f2da4d8fdd495237b..e08204ccd3c67b10c1aec1d09f76eeb71aa5b6a8 100644 (file)
       <p>If you are matching positive (<code>=</code> or <code>==</code>), you
       can capture grouped parts of the regular expression. The captured parts
       are stored in the special variables <code>$1</code> ..
-      <code>$9</code>.</p>
+      <code>$9</code>. The whole string matched by the regular expression is
+      stored in the special variable <code>$0</code></p>
 
       <example><title>Example</title>
         &lt;!--#if expr="$QUERY_STRING = /^sid=([a-zA-Z0-9]+)/" --&gt;<br />
index 9472a05e5b4a0d650cbb07d84589a304d02386a8..916e564a9d0fbdeb9a4aef7f3cee536d25e30b2e 100644 (file)
@@ -132,18 +132,20 @@ RewriteRule ^index\.html$  newsite.html
         <li>
           <strong>RewriteRule backreferences</strong>: These are
           backreferences of the form <strong><code>$N</code></strong>
-          (0 &lt;= N &lt;= 9), which provide access to the grouped
+          (0 &lt;= N &lt;= 9). $1 to $9 provide access to the grouped
           parts (in parentheses) of the pattern, from the
           <code>RewriteRule</code> which is subject to the current
-          set of <code>RewriteCond</code> conditions.
+          set of <code>RewriteCond</code> conditions. $0 provides
+          access to the whole string matched by that pattern.
         </li>
         <li>
           <strong>RewriteCond backreferences</strong>: These are
           backreferences of the form <strong><code>%N</code></strong>
-          (1 &lt;= N &lt;= 9), which provide access to the grouped
+          (0 &lt;= N &lt;= 9). %1 to %9 provide access to the grouped
           parts (again, in parentheses) of the pattern, from the last matched
           <code>RewriteCond</code> in the current set
-          of conditions.
+          of conditions. %0 provides access to the whole string matched by
+          that pattern.
         </li>
         <li>
           <strong>RewriteMap expansions</strong>: These are
index f5b9fa44ca8a7cd0a57c063511e43ed8d421c274..78d67ea1df46631dc93b5a7755b1e573cfe55628 100644 (file)
@@ -542,18 +542,20 @@ RewriteRule ^index\.html$  newsite.html
         <li>
           <strong>RewriteRule backreferences</strong>: These are
           backreferences of the form <strong><code>$N</code></strong>
-          (0 &lt;= N &lt;= 9), which provide access to the grouped
+          (0 &lt;= N &lt;= 9). $1 to $9 provide access to the grouped
           parts (in parentheses) of the pattern, from the
           <code>RewriteRule</code> which is subject to the current
-          set of <code>RewriteCond</code> conditions.
+          set of <code>RewriteCond</code> conditions. $0 provides
+          access to the whole string matched by that pattern.
         </li>
         <li>
           <strong>RewriteCond backreferences</strong>: These are
           backreferences of the form <strong><code>%N</code></strong>
-          (1 &lt;= N &lt;= 9), which provide access to the grouped
+          (0 &lt;= N &lt;= 9). %1 to %9 provide access to the grouped
           parts (again, in parentheses) of the pattern, from the last matched
           <code>RewriteCond</code> in the current set
-          of conditions.
+          of conditions. %0 provides access to the whole string matched by
+          that pattern.
         </li>
         <li>
           <strong>RewriteMap expansions</strong>: These are
index 729c754baa29acf3534b7183d6003a7332e61ebb..e645235de543db2321a0043e1042b0af8ea0f265 100644 (file)
@@ -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++;
         }