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

Nice signature. Go away


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

[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