+ */
+ function _preparse()
+ {
+ $options = HTML_BBCodeParser::getStaticProperty('HTML_BBCodeParser','_options');
+ $o = $options['open'];
+ $c = $options['close'];
+ $oe = $options['open_esc'];
+ $ce = $options['close_esc'];
+
+ $pattern = array( "!".$oe."\*".$ce."!",
+ "!".$oe."(u?)list=(?-i:A)(\s*[^".$ce."]*)".$ce."!i",
+ "!".$oe."(u?)list=(?-i:a)(\s*[^".$ce."]*)".$ce."!i",
+ "!".$oe."(u?)list=(?-i:I)(\s*[^".$ce."]*)".$ce."!i",
+ "!".$oe."(u?)list=(?-i:i)(\s*[^".$ce."]*)".$ce."!i",
+ "!".$oe."(u?)list=(?-i:1)(\s*[^".$ce."]*)".$ce."!i",
+ "!".$oe."(u?)list([^".$ce."]*)".$ce."!i");
+
+ $replace = array( $o."li".$c,
+ $o."\$1list=upper-alpha\$2".$c,
+ $o."\$1list=lower-alpha\$2".$c,
+ $o."\$1list=upper-roman\$2".$c,
+ $o."\$1list=lower-roman\$2".$c,
+ $o."\$1list=decimal\$2".$c,
+ $o."\$1list\$2".$c );
+
+ $this->_preparsed = preg_replace($pattern, $replace, $this->_text);
+ }
+}
+
+
+?>
\ No newline at end of file
diff --git a/parsers/HTML/tests/AllTests.php b/parsers/HTML/tests/AllTests.php
new file mode 100644
index 000000000..bea283420
--- /dev/null
+++ b/parsers/HTML/tests/AllTests.php
@@ -0,0 +1,36 @@
+
\ No newline at end of file
diff --git a/parsers/HTML/tests/HTML_BBCodeParserTest.php b/parsers/HTML/tests/HTML_BBCodeParserTest.php
new file mode 100644
index 000000000..50ea5ec71
--- /dev/null
+++ b/parsers/HTML/tests/HTML_BBCodeParserTest.php
@@ -0,0 +1,244 @@
+ ''));
+ $bbc->addFilter('Basic');
+ $this->basicBBCode($bbc, 'qparse');
+ $bbc->removeFilter('Basic');
+ $this->assertEquals('[b]txt[/b]', $bbc->qparse('[b]txt[/b]'), 'Basic filters have been removed.');
+ $bbc->addFilters('Basic,Email');
+ $this->basicBBCode($bbc, 'qparse');
+ $this->emailBBCode($bbc, 'qparse');
+ }
+
+ function testQparse()
+ {
+ $bbc = new HTML_BBCodeParser(array('filters' => 'Basic,Email,Extended,Images,Links,Lists'));
+ $this->basicBBCode($bbc, 'qparse');
+ $this->listBBCode($bbc, 'qparse');
+ $this->linkBBCode($bbc, 'qparse');
+ $this->extBBCode($bbc, 'qparse');
+ $this->imgBBCode($bbc, 'qparse');
+ $this->emailBBCode($bbc, 'qparse');
+ }
+
+ function emailBBCode($bbc, $funcNam)
+ {
+ $this->assertEquals('guest@anonymous.org', $bbc->$funcNam('guest@anonymous.org'));
+ $this->assertEquals('mail me', $bbc->$funcNam('[email=guest@anonymous.org]mail me[/email]'));
+ $this->assertEquals('guest@anonymous.org', $bbc->$funcNam('[email]guest@anonymous.org[/email]'));
+ }
+
+ function imgBBCode($bbc, $funcNam)
+ {
+ $this->assertEquals('', $bbc->$funcNam('[img w=100 h=99 alt=Enthalpy Wheel]/images/Enthalpy Wheel.png[/img]'));
+ $this->assertEquals('', $bbc->$funcNam('[img]img.jpg[/img]'));
+ $this->assertEquals('', $bbc->$funcNam('[img w=100 h=200]http://www.server.org/image.jpg[/img]'));
+ }
+
+ function basicBBCode($bbc, $funcNam)
+ {
+ $this->assertEquals('txt', $bbc->$funcNam('[b]txt[/b]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[b]txt'));
+ $this->assertEquals('txt', $bbc->$funcNam('[i]txt[/i]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[i]txt[/I]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[I]txt[/i]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[I]txt[/I]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[s]txt[/s]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[u]txt[/u]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[sub]txt[/sub]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[sup]txt[/sup]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[sup][sub]txt[/sup][/sub]'));
+ $this->assertEquals('txt', $bbc->$funcNam('[i][b]txt[/i][/b]'));
+ }
+
+ function listBBCode($bbc, $funcNam)
+ {
+ $this->assertEquals('', $bbc->$funcNam('[*]txt'));
+ $this->assertEquals("", $bbc->$funcNam("[ulist][*]txt\n[/ulist]"));
+ $this->assertEquals('', $bbc->$funcNam('[ulist]txt[/ulist]'));
+ $this->assertEquals('', $bbc->$funcNam('[ulist][ulist][ulist]txt'));
+ $this->assertEquals('', $bbc->$funcNam('[ulist][xxx]txt[/xxx][/ulist]'));
+ $this->assertEquals('', $bbc->$funcNam('[ulist][li]txt[/li][/ulist]'));
+ $this->assertEquals('', $bbc->$funcNam('[ulist][li]txt[li]txt[/ulist]'));
+ $this->assertEquals('', $bbc->$funcNam('[ulist][*]txt[/ulist]'));
+ $this->assertEquals('', $bbc->$funcNam('[ulist][*][list][*]txt[/ulist]'));
+ $this->assertEquals('- txt
', $bbc->$funcNam('[list][li]txt[/li][/list]'));
+ $this->assertEquals('', $bbc->$funcNam('[li][list][li]txt[/li][/list]'));
+ $this->assertEquals('', $bbc->$funcNam('[*]txt[ulist]txt[/ulist]'));
+ $this->assertEquals('', $bbc->$funcNam('[li][ulist][ulist][ulist]txt'));
+ $this->assertEquals(
+ '- ordered item 1, nested list:
- nested item 1
- nested item 2
- ordered item 2
',
+ $bbc->$funcNam('[list=A s=3][li]ordered item 1, nested list:[list=I][li]nested item 1[/li][li]nested item 2[/li][/list][/li][li]ordered item 2[/li][/list]'));
+ $this->assertEquals(
+ '- ordered item 1 type A
- ordered item 12 type A
',
+ $bbc->$funcNam('[list=A][li]ordered item 1 type A[/li][li=12]ordered item 12 type A[/li][/list]'));
+ $this->assertEquals(
+ '- ordered item 5 type a
- ordered item 6 type a
',
+ $bbc->$funcNam('[list=a s=5][li]ordered item 5 type a[/li][*]ordered item 6 type a[/list]'));
+ $this->assertEquals(
+ '- ordered item 1 type I
',
+ $bbc->$funcNam('[list=I][*]ordered item 1 type I[/list]'));
+ $this->assertEquals(
+ '- ordered item 1 type i
- ordered item 4 type i
',
+ $bbc->$funcNam('[list=i][*]ordered item 1 type i[li=4]ordered item 4 type i[/li][/list]'));
+ $this->assertEquals(
+ '- ordered item 1
- ordered item 2
',
+ $bbc->$funcNam('[list=1][*]ordered item 1[*]ordered item 2[/list]'));
+ //Bug #512: [list] in a [list] breaks the first [list]
+ $this->assertEquals(
+ '- Subject 1
- First
- Second
- Subject 2
',
+ $bbc->$funcNam('[list][*] Subject 1[list][*] First[*] Second[/list][*] Subject 2[/list]')
+ );
+ //Bug #1201: [list] output adding extra
+ $this->assertEquals(
+ '- txt
',
+ $bbc->$funcNam('[list][*]txt[/list]')
+ );
+ //Bug#6335 Empty item displayed
+ $this->assertEquals(
+ '- Item one
- Item two
- Item three
',
+ $bbc->$funcNam('[list=1][*] Item one[*] Item two[*] Item three[/list]'));
+ }
+
+ function linkBBCode($bbc, $funcNam)
+ {
+ $this->assertEquals(
+ 'http://www.test.com/',
+ $bbc->$funcNam('http://www.test.com/'));
+ $this->assertEquals(
+ 'www.test.com',
+ $bbc->$funcNam('[url]www.test.com[/url]'));
+ $this->assertEquals(
+ 'http://www.test.com/testurl',
+ $bbc->$funcNam('[url]http://www.test.com/testurl[/url]'));
+ $this->assertEquals(
+ 'testurl',
+ $bbc->$funcNam('[url=www.test.com/]testurl[/url]'));
+ $this->assertEquals(
+ 'server',
+ $bbc->$funcNam('[url=http://www.server.org t=new]server[/url]'));
+ $this->assertEquals(
+ 'txt www.test.com txt',
+ $bbc->$funcNam('txt www.test.com txt'));
+ $this->assertEquals(
+ 'txt (www.test.com) txt',
+ $bbc->$funcNam('txt (www.test.com) txt'));
+ $this->assertEquals(
+ 'txt www.test.com/test.php?a=1,2, txt',
+ $bbc->$funcNam('txt www.test.com/test.php?a=1,2, txt'));
+ $this->assertEquals(
+ 'txt www.test.com, txt',
+ $bbc->$funcNam('txt www.test.com, txt'));
+ $this->assertEquals(
+ 'txt http://www.test.com: txt',
+ $bbc->$funcNam('txt http://www.test.com: txt'));
+ $this->assertEquals(
+ 'txt www.test.com; txt',
+ $bbc->$funcNam('txt www.test.com; txt'));
+ //Bug #1755: tags around an url -> mess
+ $this->assertEquals(
+ 'txt www.test.com txt',
+ $bbc->$funcNam('txt [i]www.test.com[/i] txt'));
+ //Bug #1512: URL Tags Allow Javascript injection
+ $this->assertEquals(
+ 'Click here',
+ $bbc->$funcNam('[url=javascript:location.replace("bad_link");]Click here[/url]'));
+ $this->assertEquals(
+ 'linked text',
+ $bbc->$funcNam('[url=http://domain.com/index.php?i=1&j=2]linked text[/URL]'));
+ $this->assertEquals(
+ 'linked text',
+ $bbc->$funcNam('[url=http://domain.com/index.php?i=1&j=2]linked text[/URL]'));
+ //Bug #5609: BBCodeParser allows XSS
+ $this->assertEquals(
+ 'Alert box with "CouCou"',
+ $bbc->$funcNam('[url=javascript://%0ASh=alert(%22CouCou%22);window.close();]Alert box with "CouCou"[/url]')
+ );
+ /*
+ //Request #4936: Nested URLs in quotes not handled
+ $this->assertEquals(
+ 'Quoted text
', //?!?!?
+ $bbc->$funcNam('[quote="[url=http://somewhere.com]URL-Title[/url]"]Quoted text[/quote]')
+ );
+ */
+ }
+
+ function extBBCode($bbc, $funcNam)
+ {
+ $this->assertEquals('txt
', $bbc->$funcNam('[h2]txt[/h2]'));
+ $this->assertEquals('blue text', $bbc->$funcNam('[color=blue]blue text[/color]'));
+ $this->assertEquals('the size of this text is 18pt', $bbc->$funcNam('[size=18]the size of this text is 18pt[/size]'));
+ $this->assertEquals('different font type', $bbc->$funcNam('[font=arial]different font type[/font]'));
+ $this->assertEquals('yes, you\'re right, this isn\'t on the left
', $bbc->$funcNam('[align=right]yes, you\'re right, this isn\'t on the left[/align]'));
+ $this->assertEquals('he said: i\'m tony montana
', $bbc->$funcNam('he said: [quote=http://www.server.org/quote.html]i\'m tony montana[/quote]'));
+ $this->assertEquals('x + y = 6;
', $bbc->$funcNam('[code]x + y = 6;[/code]'));
+ //Bug #1258: Extra tags rendered with faulty BBCode
+ $this->assertEquals(
+ 'my name NeverMind!',
+ $bbc->$funcNam('[font=Verdana][color=red]my name NeverMind![/font][/color]')
+ );
+ //Bug #1979: Whitespaces in attribute are breaking it
+ $this->assertEquals(
+ 'txt',
+ $bbc->$funcNam('[font=Comic Sans MS]txt[/font]')
+ );
+ //Bug #4844: Arbitrary HTML injection
+ $this->assertEquals(
+ '',
+ $bbc->$funcNam('[align=foo">][/align]')
+ );
+ }
+
+
+
+ /**
+ * An empty had been included for the first space
+ */
+ function testBug11400()
+ {
+ $bbc = new HTML_BBCodeParser(array('filters' => ''));
+ $bbc->addFilter('Lists');
+
+ //this works
+ $this->assertEquals('',
+ $bbc->qparse("[ulist][*]one[*]two[/ulist]")
+ );
+ //this not
+ $this->assertEquals('',
+ $bbc->qparse("[ulist] [*]one[*]two[/ulist]")
+ );
+ //this not
+ $this->assertEquals('- one
- two
',
+ $bbc->qparse("[list] [*]one[*]two[/list]")
+ );
+ }
+
+
+
+ /**
+ * img tags didn't like = in url
+ */
+ function testBug11370()
+ {
+ $bbc = new HTML_BBCodeParser(array('filters' => ''));
+ $bbc->addFilter('Images');
+
+ $this->assertEquals('',
+ $bbc->qparse("[img]admin.php?fs=image[/img]")
+ );
+ }
+}
+
+//Run tests if run from the command line
+if (realpath($_SERVER['PHP_SELF']) == __FILE__){
+ $suite = new PHPUnit_TestSuite('BBCodeParser_TestCase');
+ $result = PHPUnit::run($suite);
+ echo $result->toString();
+}
+?>
\ No newline at end of file