rse         99/10/27 02:03:00

  Modified:    src      CHANGES
               src/modules/standard mod_rewrite.c
  Log:
  Overhauled mod_rewrite's general substitution function
  (expand_backref_inbuffer): 1. The `$0' backreference is now officially allowed
  and documented and references the while pattern space; 2. the ampersamp (&)
  backreference (which is equal to $0) is no longer expanded, because it was
  never documented and only leads to confusion with QUERY_STRINGS; 3.
  backslashes (\) are honored correctly, that is `\$N' now really forces the
  dollar to be an ordinary character and $N is not expanded.
  
  Submitted by: Ralf S. Engelschall
  PR: 4766 4161
  
  Revision  Changes    Path
  1.1442    +10 -0     apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1441
  retrieving revision 1.1442
  diff -u -r1.1441 -r1.1442
  --- CHANGES   1999/10/27 08:10:06     1.1441
  +++ CHANGES   1999/10/27 09:02:43     1.1442
  @@ -1,5 +1,15 @@
   Changes with Apache 1.3.10
   
  +  *) Overhauled mod_rewrite's general substitution function
  +     (expand_backref_inbuffer): 1. The `$0' backreference is now officially
  +     allowed and documented and references the while pattern space; 2. the
  +     ampersamp (&) backreference (which is equal to $0) is no longer 
expanded,
  +     because it was never documented and only leads to confusion with
  +     QUERY_STRINGS; 3. backslashes (\) are honored correctly, that is `\$N'
  +     now really forces the dollar to be an ordinary character and $N is
  +     not expanded. 
  +     [Ralf S. Engelschall] PR#4766 PR#4161
  +
     *) Make sure mod_rewrite escapes QUERY_STRINGS on redirects.
        [Klaus Johannes Rusch <[EMAIL PROTECTED]>] PR#4734
   
  
  
  
  1.149     +24 -21    apache-1.3/src/modules/standard/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
  retrieving revision 1.148
  retrieving revision 1.149
  diff -u -r1.148 -r1.149
  --- mod_rewrite.c     1999/10/27 08:18:58     1.148
  +++ mod_rewrite.c     1999/10/27 09:02:49     1.149
  @@ -2493,34 +2493,37 @@
   static void expand_backref_inbuffer(pool *p, char *buf, int nbuf,
                                       backrefinfo *bri, char c)
   {
  -    int i;
  +    register int i;
   
  -    if (bri->nsub < 1) {
  -        return;
  -    }
  -
  -    if (c != '$') {
  -        /* safe existing $N backrefs and replace <c>N with $N backrefs */
  -        for (i = 0; buf[i] != '\0' && i < nbuf; i++) {
  -            if (buf[i] == '$' && (buf[i+1] >= '0' && buf[i+1] <= '9')) {
  -                buf[i++] = '\001';
  -            }
  -            else if (buf[i] == c && (buf[i+1] >= '0' && buf[i+1] <= '9')) {
  -                buf[i++] = '$';
  -            }
  +    /* protect existing $N and & backrefs and replace <c>N with $N backrefs 
*/
  +    for (i = 0; buf[i] != '\0' && i < nbuf; i++) {
  +        if (buf[i] == '\\' && (buf[i+1] != '\0' && i < (nbuf-1))) {
  +            i++; /* protect next */
  +        }
  +        else if (buf[i] == '&') {
  +            buf[i] = '\001';
           }
  +        else if (c != '$' && buf[i] == '$' && (buf[i+1] >= '0' && buf[i+1] 
<= '9')) {
  +            buf[i] = '\002';
  +            i++; /* speedup */
  +        }
  +        else if (buf[i] == c && (buf[i+1] >= '0' && buf[i+1] <= '9')) {
  +            buf[i] = '$';
  +            i++; /* speedup */
  +        }
       }
   
  -    /* now apply the pregsub() function */
  +    /* now apply the standard regex substitution function */
       ap_cpystrn(buf, ap_pregsub(p, buf, bri->source,
                                  bri->nsub+0, bri->regmatch), nbuf);
   
  -    if (c != '$') {
  -        /* restore the original $N backrefs */
  -        for (i = 0; buf[i] != '\0' && i < nbuf; i++) {
  -            if (buf[i] == '\001' && (buf[i+1] >= '0' && buf[i+1] <= '9')) {
  -                buf[i++] = '$';
  -            }
  +    /* restore the original $N and & backrefs */
  +    for (i = 0; buf[i] != '\0' && i < nbuf; i++) {
  +        if (buf[i] == '\001') {
  +            buf[i] = '&';
  +        }
  +        else if (buf[i] == '\002') {
  +            buf[i] = '$';
           }
       }
   }
  
  
  

Reply via email to