Page 1 of 1

problem with markup: bbcode

Posted: Fri Mar 03, 2006 4:25 pm
by costa
problem with commas inside link in bbcode markup plugin. an example:

Code: Select all

[url=http://www.s9y.org/forums/viewforum.php?f=3]link[/url]
this goes with no problems and produces this: link

but here we go with other link:

Code: Select all

[url=http://wiadomosci.gazeta.pl/wiadomosci/1,53600,3193628.html]other link[/url]
and it will not be parsed and the sentence "other link" will not be linked. actually nothing will happen and you'll see all the bbcode markup line. how to pass this problem? checked on latest version of plugin available (2.01) in comments and entry fields.

Posted: Sat Mar 04, 2006 8:35 pm
by SHRIKEE
ive seen this before on other scripts its a flaw created by the bbcode parsing script.

might be seen as a bug :(
I believe its more like a flaw in php's preg_replace() for not recognizing the characters correctly

{edit!!}
This code does recognize multiple urls. However i have no idea on how to implemente it in s9y. Maybe ill look into it more later. Or some of the developers can? I think it will be nice replacement for the default markup code and in my ideas should be inplemented by default and not as plugin.

function BBCode($text) {
// Check illegal tags (leave here at this exact point or the BBCode will not work properly)
$text=strip_tags($text);

/*---- URLs, Emails and Images ----*/
// Url scanner and replacer (urls with no [url] tags)
//$text=preg_replace("/\s(www\.)(.*?)/"," <a href='http://$1$2' target='_blank'>$1$2</a>", $text);
//$text=preg_replace("/\s(\w+:\/\/)(.*?)/"," <a href='$1$2' target='_blank'>$1$2</a>", $text);

//url with tags, without http:// (urls with [url] tags)
$text=preg_replace("/\[url\=(www\.)(.*?)\](.*?)\[\/url\]/is","<a href='http://$1$2' target='_blank'>$3</a>",$text);
$text=preg_replace("/\[url\](www\.)(.*?)\[\/url\]/is","<a href='http://$1$2' target='_blank'>$1$2</a>",$text);

//url with tags, with http:// (urls with [url] tags)
$text=preg_replace("/\[url\=(\w+:\/\/)(.*?)\](.*?)\[\/url\]/is","<a href='$1$2' target='_blank'>$3</a>",$text);
$text=preg_replace("/\[url\](\w+:\/\/)(.*?)\[\/url\]/is","<a href='$1$2' target='_blank'>$1$2</a>",$text);

// Email scanner and replacer (addresses with no [mail] tags)
$text=preg_replace("/(\\S+@\\S+\\.\\w+)/","<a href='mailto:$1'>$1</a>",$text);

// Images
$text=preg_replace("/\[img\](.+?)\[\/img\]/is", "<table class='imagetable' cellspacing='0'><tr><td><a href='largepic.php?photoNAME=$1'><img border='0' alt='Click me for a large image' src='mods/thumbphoto.php?s=../$1&w=200&h=200'></a></td></tr><tr><td class='imagerow'><b>click to enlarge</b></td></tr></table>", $text);

/*---- Check for textstyles ----*/
// New line
$text=str_replace("\n","<br>",$text);

// Special characters
$text=str_replace("1/2","½",$text);
$text=str_replace("3/4","¾",$text);
$text=str_replace("1/4","¼",$text);
$text=str_replace("[+]","•",$text);
$text=preg_replace("(\[l\])is","<",$text);
$text=preg_replace("(\[r\])is",">",$text);

// Bold Italic Underscore Strike
$text = preg_replace("/\[([bius])\]/is", "<$1>", $text);
$text = preg_replace("/\[\/([bius])\]/is", "</$1>", $text);

// Center
$text=preg_replace("(\[center\])is","<center>",$text);
$text=preg_replace("(\[\/center\])is","</center>",$text);

// Quote and Code
$text=preg_replace("(\[quote\])is","<center><table class='quote' cellspacing='0'><tr><td><b>Quote...</b></td></tr><tr><td>",$text);
$text=preg_replace("(\[\/quote\])is","</td></tr></table></center>",$text);
$text=preg_replace("(\[code\])is","<center><table class='code' cellspacing='0'><tr><td><b>Code:</b></td></tr><tr><td>",$text);
$text=preg_replace("(\[\/code\])is","</td></tr></table></center>",$text);

// Marquee
$text=preg_replace("(\[slide\])is","<marquee>",$text);
$text=preg_replace("(\[\/slide\])is","</marquee>",$text);

// Horizontal Line
$text=preg_replace("(\[hr\])is","<hr width='95%'>",$text);
$text=preg_replace("(\[hr\=([#a-zA-Z0-9]*)\])is","<hr width='95%' color='$1'>",$text);

// Colored text
$text=preg_replace("(\[color\=([#a-zA-Z0-9]*)\])is","<font color='$1'>",$text);
$text=preg_replace("(\[\/color\])is","</font>",$text);

return $text;
}

Posted: Sun Mar 05, 2006 8:43 pm
by garvinhicking
Thanks for noticing! in fact the "," was not a valid recognized URL pattern.

In the serendipity_event_bbcode you just need to replace this:

Code: Select all

        static $pattern_url   = '([@!=~\?:&;0-9a-z#\.\-_\/]+?)';
with this:

Code: Select all

        static $pattern_url   = '([@!=~\?:&;0-9a-z#\.\-_\/,]+?)';
I've also committed this to SVN.

Regards,
Garvin

Posted: Sun Mar 05, 2006 8:54 pm
by SHRIKEE
aha!

my bad then :) ive seen several other sites having this behavior due to a flaw in the code...

Posted: Sun Mar 05, 2006 8:56 pm
by garvinhicking
Yes, Shrikkee -- you are right. BBCode is one of the most misimplemented Markups out there. With Serendipity being no difference; we've had as many XSS and Bugs in our BBCode implementation like virtually any other software :-D

Best regards,
Garvin