From 288def143cb8f594fd5c58d6a6dab07263a6c60e Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 7 Nov 2017 10:34:11 +0100 Subject: [PATCH] [ticket/15442] Allow unsafe HTML in bbcode.html PHPBB3-15442 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- tests/text_formatter/s9e/factory_test.php | 16 ++++++++ .../styles/unsafe/template/bbcode.html | 40 +++++++++++++++++++ .../s9e/fixtures/unsafe_default_bbcodes.xml | 24 +++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/text_formatter/s9e/fixtures/styles/unsafe/template/bbcode.html create mode 100644 tests/text_formatter/s9e/fixtures/unsafe_default_bbcodes.xml diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index d5ad8283d9..3a6c6ef43f 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -271,7 +271,7 @@ class factory implements \phpbb\textformatter\cache_interface // Add default BBCodes foreach ($this->get_default_bbcodes($configurator) as $bbcode) { - $configurator->BBCodes->addCustom($bbcode['usage'], $bbcode['template']); + $configurator->BBCodes->addCustom($bbcode['usage'], new UnsafeTemplate($bbcode['template'])); } if (isset($configurator->tags['QUOTE'])) { diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index fd9b4e4c09..d35330a975 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -247,6 +247,22 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $this->assertSame($expected, $renderer->render($parser->parse($original))); } + /** + * @testdox Accepts unsafe default BBCodes + */ + public function test_unsafe_default_bbcodes() + { + $fixture = __DIR__ . '/fixtures/unsafe_default_bbcodes.xml'; + $style_dir = __DIR__ . '/fixtures/styles/'; + $container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture, $style_dir); + $parser = $container->get('text_formatter.parser'); + $renderer = $container->get('text_formatter.renderer'); + + $original = '[b]alert(1)[/b]'; + $expected = ''; + $this->assertSame($expected, $renderer->render($parser->parse($original))); + } + /** * @testdox get_configurator() triggers events before and after configuration */ diff --git a/tests/text_formatter/s9e/fixtures/styles/unsafe/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/unsafe/template/bbcode.html new file mode 100644 index 0000000000..f3932f9b78 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles/unsafe/template/bbcode.html @@ -0,0 +1,40 @@ +