You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Matt Hoskins <ma...@nipltd.com> on 1999/03/29 14:27:40 UTC

mod_rewrite/4161: $0 can't be used in the substitution if there are no subexpressions

>Number:         4161
>Category:       mod_rewrite
>Synopsis:       $0 can't be used in the substitution if there are no subexpressions
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Class:          sw-bug
>Submitter-Id:   apache
>Arrival-Date:   Mon Mar 29 04:30:01 PST 1999
>Last-Modified:
>Originator:     matt@nipltd.com
>Organization:
apache
>Release:        1.3.6
>Environment:
SunOS 5.5.1
>Description:
In the function expand_backref_inbuffer in mod_rewrite.c the function has:
if(bri->nsub<1) {
    return;
}

I suspect this is put in as an optimisation to mean that if there are no
subexpressions in the pattern, don't bother trying to substitute in back
references. However this means if you have a pattern with no subexpressions and
wish to use $0 in the substitution, you just get "$0" dumped straight in.

This is of course trivial to get around by making sure there is a subexpression
in the pattern, however it is an inconsistancy.
>How-To-Repeat:
RewriteRule /wibble/* http://someserver.somewhereelse.com$0 [R,L]

This will redirect accessing /wibble/wobble to http://someserver.somewhereelse.com$0

If you change the pattern to be:
(/)wibble/*      and it doesn't matter really where you put the subexpression brackets, then it will work
Then it works.
>Fix:
If you'd rather not change the way the code works, it would be helpful to
document the inconsistancy somewhere. A simple way to fix it would be to remove
the 3 line check on nsub. An alternative way I guess would be to note if there's 
a $0 in the substitution, in the case where nsub is zero.
>Audit-Trail:
>Unformatted:
[In order for any reply to be added to the PR database, ]
[you need to include <ap...@Apache.Org> in the Cc line ]
[and leave the subject line UNCHANGED.  This is not done]
[automatically because of the potential for mail loops. ]
[If you do not include this Cc, your reply may be ig-   ]
[nored unless you are responding to an explicit request ]
[from a developer.                                      ]
[Reply only with text; DO NOT SEND ATTACHMENTS!         ]