#33437 [NEW]: comments throwing preg_replace script
| From: | php at karsites dot net | Date: | Wed, 22 Jun 2005 15:47:27 +0000 |
| Subject: | #33437 [NEW]: comments throwing preg_replace script | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-80834@lists.php.net to get a copy of this message | ||
From: php at karsites dot net
Operating system: SuSE Linux 9.2 pro
PHP version: 4.3.10
PHP Bug Type: PCRE related
Bug description: comments throwing preg_replace script
Description:
------------
I'm actually on php4-4.3.8-8.7 - stuck with that at the
moment,as that ships with my Linux distro - SuSE 9.2 pro
I did search the database for 'coments' but found nothing
there regarding this possible bug.
The code below trashes the script with the
commented line in the script
// original regex $regex = "!(</?)(\w+)([^>]*?>)!e";
Surely, everything to the right of // should be ignored
as a comment?
With the comment in place, the script produces the
following trashed output:
)!e"; $regex = "!(]*?>)!e"; $replacement =
"'\\1'.strtolower('\\2').'\\3'"; $subject = " A
rose"; echo
"Before replacement \$subject is: $subject
"; $new_sub = preg_replace($regex, $replacement, $subject);
echo "After replacement \$subject is: $new_sub
"; ?>
Is this a bug, because it is not expected behaviour.
If I remove the offending comment, the script produces the
correct output.
Regards - Keith Roberts
Reproduce code:
---------------
<?php
// original regex $regex = "!(</?)(\w+)([^>]*?>)!e";
$regex = "!(</?)(\w+)([^>]*?>)!e";
$replacement = "'\\1'.strtolower('\\2').'\\3'";
$subject = "<BIGTEXT> A <BIGGEST>rose</BIGGEST>
<PARA></BIGTEXT>";
echo "Before replacement \$subject is: $subject <br />";
$new_sub = preg_replace($regex, $replacement, $subject);
echo "After replacement \$subject is: $new_sub <br />";
?>
Expected result:
----------------
Before replacement $subject is: A rose
After replacement $subject is: A rose
(the browser ignores the dummy tags, but the correct result
can be seen with 'view source code' - ie lowercased tags)
Actual result:
--------------
)!e"; $regex = "!(]*?>)!e"; $replacement =
"'\\1'.strtolower('\\2').'\\3'"; $subject = " A
rose"; echo
"Before replacement \$subject is: $subject
"; $new_sub = preg_replace($regex, $replacement, $subject);
echo "After replacement \$subject is: $new_sub
"; ?>
--
Edit bug report at http://bugs.php.net/?id=33437&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33437&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33437&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33437&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33437&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33437&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33437&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33437&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33437&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33437&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33437&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=33437&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=33437&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33437&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33437&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33437&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33437&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33437&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33437&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33437&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33437&r=mysqlcfg