You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Victor Porton <po...@narod.ru> on 2009/09/15 12:41:23 UTC

[users@httpd] Word boundaries in regexps (Apache bug?)

Apache 2.2.13
http://localhost/test.shtml?city
Test 1 passed. Test 2 failed.

test.shtml follows

<<<<

<!--#if expr="$QUERY_STRING = /city/" -->
  Test 1 passed.
<!--#else -->
  Test 1 failed.
<!--#endif -->
<!--#if expr="$QUERY_STRING = /\bcity\b/" -->
  Test 2 passed.
<!--#else -->
  Test 2 failed.
<!--#endif -->

>>>>

So test 2 is failed.
Why \b for word boundaries doesn't work?
Is it a bug of Apache? How I specify word boundaries in regexps?

-- 
Victor Porton - http://portonvictor.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by Torsten Foertsch <to...@gmx.net>.
On Tue 15 Sep 2009, Nick Kew wrote:
> > /\\bcity\\b/ works on my localhost (Debian Linux with Apache
> > 2.2.13-1),
>
> Good.  Mystery solved (though I have to confess I'm a little
> surprised you need that in the context).

Here is the piece of code that (I believe) eats the backslashes (mod_include.c:
get_ptoken()). token->value is the start of the string, p the end. shift is
the number of unescaped backslashes found in the string.

        apr_size_t len = p - token->value - shift;
        char *c = apr_palloc(ctx->dpool, len + 1);

        p = token->value;
        token->value = c;

        while (shift--) {
            const char *e = ap_strchr_c(p, '\\');  /* move e to the next backslash */

            memcpy(c, p, e-p);                     /* copy up to the backslash excluding it */
            c   += e-p;                            /* now c points to the end of the destination string */
            *c++ = *++e;                           /* copy there the char that comes *after* the '\' and forget about the '\' */
            len -= e-p;
            p    = e+1;
        }

        if (len) {
            memcpy(c, p, len);
        }
        c[len] = '\0';

Torsten

-- 
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by Nick Kew <ni...@webthing.com>.
Victor Porton wrote:
> On Tue, 2009-09-15 at 15:05 +0200, Torsten Foertsch wrote: 
>> On Tue 15 Sep 2009, Victor Porton wrote:
>>>> <!--#if expr="$QUERY_STRING = /(^|\b)city(\b|$)/" -->
>>> After this change the test 2 passes, but it does not pass if I enter
>>> http://localhost/test2.shtml?city=2
>> Perhaps you have to outwit the SSI string parser. Just a guess:
>>
>>   <!--#if expr="$QUERY_STRING = /\\bcity\\b/" -->
> 
> /\\bcity\\b/ works on my localhost (Debian Linux with Apache 2.2.13-1),

Good.  Mystery solved (though I have to confess I'm a little
surprised you need that in the context).

> but does not work on http://logostudio.co.il/test.html?city with Apache
> 1.3.41 (FreeBSD).

As I told you earlier on IRC, 1.3 used a pre-PCRE regexp engine.

-- 
Nick Kew

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by Victor Porton <po...@narod.ru>.
On Tue, 2009-09-15 at 15:05 +0200, Torsten Foertsch wrote: 
> On Tue 15 Sep 2009, Victor Porton wrote:
> > > <!--#if expr="$QUERY_STRING = /(^|\b)city(\b|$)/" -->
> >
> > After this change the test 2 passes, but it does not pass if I enter
> > http://localhost/test2.shtml?city=2
> 
> Perhaps you have to outwit the SSI string parser. Just a guess:
> 
>   <!--#if expr="$QUERY_STRING = /\\bcity\\b/" -->

/\\bcity\\b/ works on my localhost (Debian Linux with Apache 2.2.13-1),
but does not work on http://logostudio.co.il/test.html?city with Apache
1.3.41 (FreeBSD).

-- 
Victor Porton - http://portonvictor.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by André Warnier <aw...@ice-sa.com>.
Torsten Foertsch wrote:
> Привет,
> 
> On Tue 15 Sep 2009, Victor Porton wrote:
>>> <!--#if expr="$QUERY_STRING = /(^|\b)city(\b|$)/" -->
>> After this change the test 2 passes, but it does not pass if I enter
>> http://localhost/test2.shtml?city=2
> 
> Perhaps you have to outwit the SSI string parser. Just a guess:
> 
>   <!--#if expr="$QUERY_STRING = /\\bcity\\b/" -->
> 
Yep, my bet would be on that one too right now.

If not, (but admittedly we can keep going on like this) :

<!--#if expr="$QUERY_STRING = /(^|\b)city(\b|$|=)/" -->

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by Torsten Foertsch <to...@gmx.net>.
Привет,

On Tue 15 Sep 2009, Victor Porton wrote:
> > <!--#if expr="$QUERY_STRING = /(^|\b)city(\b|$)/" -->
>
> After this change the test 2 passes, but it does not pass if I enter
> http://localhost/test2.shtml?city=2

Perhaps you have to outwit the SSI string parser. Just a guess:

  <!--#if expr="$QUERY_STRING = /\\bcity\\b/" -->

Torsten

-- 
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by Victor Porton <po...@narod.ru>.
On Tue, 2009-09-15 at 13:29 +0200, André Warnier wrote:
> Tom Evans wrote:
> > On Tue, 2009-09-15 at 12:52 +0200, André Warnier wrote:
> >> Victor Porton wrote:
> >> ...
> >>> <!--#if expr="$QUERY_STRING = /city/" -->
> >> I am not sure which add-on module of Apache, and which version you are 
> >> talking about, but are you sure that the above right-hand side is 
> >> interpreted as a regexp, as opposed to a simple string ?
> >> Can you point us to the relevant documentation ?
> >>
> >>
> >>
> > 
> > http://httpd.apache.org/docs/2.2/mod/mod_include.html#flowctrl
> > 
> > string1 = string2
> > string1 == string2
> > string1 != string2
> >         
> >         Compare string1 with string2. If string2 has the form /string2/
> >         then it is treated as a regular expression. Regular expressions
> >         are implemented by the PCRE engine and have the same syntax as
> >         those in perl 5. Note that == is just an alias for = and behaves
> >         exactly the same way.
> >         
> > No idea why it isn't working for him.
> > 
> Allright then.  And neither have I.
> Victor, what about this for test #2 :
> <!--#if expr="$QUERY_STRING = /(^|\b)city(\b|$)/" -->

After this change the test 2 passes, but it does not pass if I enter
http://localhost/test2.shtml?city=2
(I need it to pass in this case also.)

BTW, I am about Apache 2.2.13 Linux.

-- 
Victor Porton - http://portonvictor.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by André Warnier <aw...@ice-sa.com>.
Tom Evans wrote:
> On Tue, 2009-09-15 at 12:52 +0200, André Warnier wrote:
>> Victor Porton wrote:
>> ...
>>> <!--#if expr="$QUERY_STRING = /city/" -->
>> I am not sure which add-on module of Apache, and which version you are 
>> talking about, but are you sure that the above right-hand side is 
>> interpreted as a regexp, as opposed to a simple string ?
>> Can you point us to the relevant documentation ?
>>
>>
>>
> 
> http://httpd.apache.org/docs/2.2/mod/mod_include.html#flowctrl
> 
> string1 = string2
> string1 == string2
> string1 != string2
>         
>         Compare string1 with string2. If string2 has the form /string2/
>         then it is treated as a regular expression. Regular expressions
>         are implemented by the PCRE engine and have the same syntax as
>         those in perl 5. Note that == is just an alias for = and behaves
>         exactly the same way.
>         
> No idea why it isn't working for him.
> 
Allright then.  And neither have I.
Victor, what about this for test #2 :
<!--#if expr="$QUERY_STRING = /(^|\b)city(\b|$)/" -->


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by Tom Evans <te...@googlemail.com>.
On Tue, 2009-09-15 at 12:52 +0200, André Warnier wrote:
> Victor Porton wrote:
> ...
> > 
> > <!--#if expr="$QUERY_STRING = /city/" -->
> 
> I am not sure which add-on module of Apache, and which version you are 
> talking about, but are you sure that the above right-hand side is 
> interpreted as a regexp, as opposed to a simple string ?
> Can you point us to the relevant documentation ?
> 
> 
> 

http://httpd.apache.org/docs/2.2/mod/mod_include.html#flowctrl

string1 = string2
string1 == string2
string1 != string2
        
        Compare string1 with string2. If string2 has the form /string2/
        then it is treated as a regular expression. Regular expressions
        are implemented by the PCRE engine and have the same syntax as
        those in perl 5. Note that == is just an alias for = and behaves
        exactly the same way.
        
No idea why it isn't working for him.

Cheers

Tom


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Word boundaries in regexps (Apache bug?)

Posted by André Warnier <aw...@ice-sa.com>.
Victor Porton wrote:
...
> 
> <!--#if expr="$QUERY_STRING = /city/" -->

I am not sure which add-on module of Apache, and which version you are 
talking about, but are you sure that the above right-hand side is 
interpreted as a regexp, as opposed to a simple string ?
Can you point us to the relevant documentation ?



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org