diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php
index 4e535b8d..50ad3838 100644
--- a/ext/bbcode/main.php
+++ b/ext/bbcode/main.php
@@ -14,12 +14,12 @@ class BBCode implements Extension {
$text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text);
$text = preg_replace("/\[s\](.*?)\[\/s\]/s", "\\1", $text);
$text = preg_replace("/\[code\](.*?)\[\/code\]/s", "
\\1", $text); - $text = preg_replace("/>>(\d+)/s", ">>\\1", $text); + $text = preg_replace("/>>(\d+)/s", ">>\\1", $text); $text = preg_replace("/>>([^\d].+)/", "
\\1", $text); - $text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "\\2", $text); - $text = preg_replace("/\[url\]((?:https?|ftp|irc|mailto):\/\/.*?)\[\/url\]/s", "\\1", $text); - $text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "\\2", $text); - $text = preg_replace("/\[\[([^\]]+)\]\]/s", "\\1", $text); + $text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "\\2", $text); + $text = preg_replace("/\[url\]((?:https?|ftp|irc|mailto):\/\/.*?)\[\/url\]/s", "\\1", $text); + $text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "\\2", $text); + $text = preg_replace("/\[\[([^\]]+)\]\]/s", "\\1", $text); $text = str_replace("\n", "\n
\\1", $text); $text = preg_replace("/\[quote=(.*?)\](.*?)\[\/quote\]/s", "Quoting \\1
\\2", $text); diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php new file mode 100644 index 00000000..18348440 --- /dev/null +++ b/ext/bbcode/test.php @@ -0,0 +1,35 @@ +template("[b]bold[/b][i]italic[/i]", "bolditalic"); + } + + public function testStacking() { + $this->template("[b]B[/b][i]I[/i][b]B[/b]", "BIB"); + $this->template("[b]bold[i]bolditalic[/i]bold[/b]", "boldbolditalicbold"); + } + + public function testFailure() { + $this->template("[b]bold[i]italic", "[b]bold[i]italic"); + } + + public function testURL() { + $this->template( + "[url]http://shishnet.org[/url]", + "http://shishnet.org"); + $this->template( + "[url=http://shishnet.org]ShishNet[/url]", + "ShishNet"); + $this->template( + "[url=javascript:alert(\"owned\")]click to fail[/url]", + "[url=javascript:alert("owned")]click to fail[/url]"); + } + + private function template($in, $out) { + $bb = new BBCode(); + $tfe = new TextFormattingEvent($in); + $bb->receive_event($tfe); + $this->assertEqual($tfe->formatted, $out); + } +} +?>