#33437 [Opn->Bgs]: comments throwing preg_replace script
| From: | tony2001@php.net | Date: | Wed, 22 Jun 2005 16:04:11 +0000 |
| Subject: | #33437 [Opn->Bgs]: comments throwing preg_replace script | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-80841@lists.php.net to get a copy of this message | ||
ID: 33437
Updated by: tony2001@php.net
Reported By: php at karsites dot net
-Status: Open
+Status: Bogus
Bug Type: PCRE related
Operating System: SuSE Linux 9.2 pro
PHP Version: 4.3.10
New Comment:
So, no bug here -> bogus.
Previous Comments:
------------------------------------------------------------------------
[2005-06-22 18:01:12] php at karsites dot net
Woops!
I've just noticed the ?> in the regular expression.
Obviously, this has been recognised as the 'back to html
mode' php tag!
Keith
------------------------------------------------------------------------
[2005-06-22 17:52:29] tony2001@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php4-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
------------------------------------------------------------------------
[2005-06-22 17:47:26] php at karsites dot net
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 this bug report at http://bugs.php.net/?id=33437&edit=1