From:             willn at umich dot edu
Operating system: Solaris 5.8
PHP version:      4.3.2
PHP Bug Type:     Regexps related
Bug description:  regular expression order matters when it shouldn't

Description:
------------
Within the "anti-match" square brackets, order shouldn't make a
difference, but it does. I'm writing a simple anti-injection attack filter
to pull out all the illegal characters, and leave the ones that I want.
Unfortunately, I found that with this particular combination, I've been
getting this error message:

[Thu Nov 13 14:25:41 2003] [error] PHP Warning:  Compilation failed: range
out of order in character class at offset 4 in
/usr/local/projects/vote-dev/public/test.php on line 5

The code below demonstrates the simplest case I could find that would
replicate the problem. Swapping the order a little bit makes it work a
little better - as you can see that the $a and $f variables have some
issues.


Reproduce code:
---------------
<pre><?php
    $text = 'This, is my - "favorite".';
    $a = preg_replace( '/[^,-"]/', '', $text );
    $b = preg_replace( '/[^,"-]/', '', $text );
    $c = preg_replace( '/[^-,"]/', '', $text );
    $d = preg_replace( '/[^-",]/', '', $text );
    $e = preg_replace( '/[^",-]/', '', $text );
    $f = preg_replace( '/[^"-,]/', '', $text );
    echo "$text\na:$a\nb:$b\nc:$c\nd:$d\ne:$e\nf:$f";
?></pre>

Expected result:
----------------
This, is my - "favorite".
a:,-""
b:,-""
c:,-""
d:,-""
e:,-""
f:,-""

Actual result:
--------------
This, is my - "favorite".
a:
b:,-""
c:,-""
d:,-""
e:,-""
f:,""

-- 
Edit bug report at http://bugs.php.net/?id=26244&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=26244&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=26244&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=26244&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=26244&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=26244&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=26244&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=26244&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=26244&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=26244&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=26244&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=26244&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26244&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=26244&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=26244&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=26244&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26244&r=float

Reply via email to