ID:               25512
 Updated by:       [EMAIL PROTECTED]
 Reported By:      koni at 2complex dot net
 Status:           Bogus
 Bug Type:         Reproducible crash
 Operating System: Windows XP
 PHP Version:      4.3.3
 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Your code is inherently flawed.  What you describe can be correctly
handled with a single regex expression (albiet a complex one).

However since this is a bug reporting database and not a support forum,
I suggest you try one of the resources named in the paragraphs above. 


Previous Comments:
------------------------------------------------------------------------

[2003-09-12 09:00:57] koni at 2complex dot net

hey, this is a SERIOUS BUG REPORT, PHP can NOT preg_replace this code.
I am sorry if this was the text that the user submitted in my forum and
I dont know how to reproduce the problem with another code so I had to
submit the original Code.

I am sorry if you feel offended but I think you should be a lot more
objective about this problem. Forget about the content and look at the
bug.

------------------------------------------------------------------------

[2003-09-12 08:19:34] [EMAIL PROTECTED]

Nice signature. Go away

------------------------------------------------------------------------

[2003-09-12 07:15:15] koni at 2complex dot net

Description:
------------
I wanted to write a vbb code style for a new forum and I used nl2br to
format the mysql data into html. As there was a special [code] ...
[/code] area in my vbb code which used the html <pre> ... </pre>
command the format the spaces correctly, I saw that nl2br changes \n
into <br />\n and therefor <pre> shows 2 lines instead of 1. As there
1. is no option for nl2br to either replace with <br /> or < br/>\n, I
wrote a small Code to preg_replace the code between the [code] ..
[/code] commands with a placeholder, then nl2br the whole thing and
then replace the placeholder again with the code. This did work fine
... until I used the following ascii figure between the [code]
commands:

* g o a t s e x * g o a t s e x * g o a t s e x * 
g                                               g  
o /     \             \            /    \       o  
a|       |             \          |      |      a  
t|       `.             |         |       :     t  
s`        |             |        \|       |     s  
e \       | /       /  \   --__ \       :    e  
x  \      \/   _--~~          ~--__| \     |    x  
*   \      \_-~                    ~-_\    |    *  
g    \_     \        _.--------.______\|   |    g  
o      \     \______// _ ___ _ (_(__>  \   |    o  
a       \   .  C ___)  ______ (_(____>  |  /    a  
t       /\ |   C ____)/      \ (_____>  |_/     t  
s      / /\|   C_____)       |  (___>   /  \    s  
e     |   (   _C_____)\______/  // _/ /     \   e  
x     |    \  |__   \_________// (__/       |   x  
*    | \    \____)   `----   --'             |  *  
g    |  \_          ___\       /_          _/  | g  
o   |              /    |     |  \             | o  
a   |             |    /       \  \            | a  
t   |          / /    |         |  \           |t  
s   |         / /      \__/\___/    |          |s  
e  |         / /        |    |       |         |e  
x  |          |         |    |       |         |x  
* g o a t s e x * g o a t s e x * g o a t e x *

This gave me the following:

Warning: Compilation failed: missing ) at offset 1412 in
c:\phpdev\www\tattered\functions.php on line 788

and line 788 is:

$message =
preg_replace("#".escape($match)."#si","##$counter##",$message);

Every preg_replace crashes when it has to replace the above-mentioned
code.

Reproduce code:
---------------
function escape($string) {
    $list = array("[" => "\[", "]" => "\]", "/" => "\/");
    foreach($list as $search => $replace) {
        $string = str_replace($search, $replace, $string);
    }
    return $string;
}

       
preg_match_all("#\[code\]([^\[]*)\[\/code\]#si",$message,$matches);

        foreach($matches[0] as $counter => $match) {
            $message =
preg_replace("#".escape($match)."#si","##$counter##",$message);
        }
        $message = nl2br($message);
        foreach($matches[0] as $counter => $match) {
           $message =
preg_replace("/##$counter##/si",$match,$message);
        }


Expected result:
----------------
 g o a t s e x * g o a t s e x * g o a t s e x * 
g                                               g  
o /     \             \            /    \       o  
a|       |             \          |      |      a  
t|       `.             |         |       :     t  
s`        |             |        \|       |     s  
e \       | /       /  \   --__ \       :    e  
x  \      \/   _--~~          ~--__| \     |    x  
*   \      \_-~                    ~-_\    |    *  
g    \_     \        _.--------.______\|   |    g  
o      \     \______// _ ___ _ (_(__>  \   |    o  
a       \   .  C ___)  ______ (_(____>  |  /    a  
t       /\ |   C ____)/      \ (_____>  |_/     t  
s      / /\|   C_____)       |  (___>   /  \    s  
e     |   (   _C_____)\______/  // _/ /     \   e  
x     |    \  |__   \_________// (__/       |  x  
*    | \    \____)   `----   --'             |  *  
g    |  \_          ___\       /_          _/ | g  
o   |              /    |     |  \            | o  
a   |             |    /       \  \           | a  
t   |          / /    |         |  \           |t  
s   |         / /      \__/\___/    |                  |s  
e  |         / /        |    |       |                    |e  
x  |          |         |    |       |                    |x  
* g o a t s e x * g o a t s e x * g o a t e x *


Actual result:
--------------
 g o a t s e x * g o a t s e x * g o a t s e x * 

g                                               g  

o /     \             \            /    \       o  

a|       |             \          |      |      a  

t|       `.             |         |       :     t  

s`        |             |        \|       |     s  

e \       | /       /  \   --__ \       :    e  

x  \      \/   _--~~          ~--__| \     |    x  

*   \      \_-~                    ~-_\    |    *  

g    \_     \        _.--------.______\|   |    g  

o      \     \______// _ ___ _ (_(__>  \   |    o  

a       \   .  C ___)  ______ (_(____>  |  /    a  

t       /\ |   C ____)/      \ (_____>  |_/     t  

s      / /\|   C_____)       |  (___>   /  \    s  

e     |   (   _C_____)\______/  // _/ /     \   e  

x     |    \  |__   \_________// (__/       |  x  

*    | \    \____)   `----   --'             |  *  

g    |  \_          ___\       /_          _/ | g  

o   |              /    |     |  \            | o  

a   |             |    /       \  \           | a  

t   |          / /    |         |  \           |t  

s   |         / /      \__/\___/    |                  |s  

e  |         / /        |    |       |                    
|e  
x  |          |         |    |       |                    
|x  
* g o a t s e x * g o a t s e x * g o a t e x *




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25512&edit=1

Reply via email to