Skip to content

Commit

Permalink
Merge branch '3.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
marc1706 committed Jan 25, 2018
2 parents 2053399 + c89051e commit a24a8a6
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 14 deletions.
1 change: 1 addition & 0 deletions phpBB/config/default/container/services_text_formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
- '@dispatcher'
- '@config'
- '@text_formatter.s9e.link_helper'
- '@log'
- '%text_formatter.cache.dir%'
- '%text_formatter.cache.parser.key%'
- '%text_formatter.cache.renderer.key%'
Expand Down
1 change: 1 addition & 0 deletions phpBB/language/en/acp/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@
'LOG_BBCODE_ADD' => '<strong>Added new BBCode</strong><br />» %s',
'LOG_BBCODE_EDIT' => '<strong>Edited BBCode</strong><br />» %s',
'LOG_BBCODE_DELETE' => '<strong>Deleted BBCode</strong><br />» %s',
'LOG_BBCODE_CONFIGURATION_ERROR' => '<strong>Error while configuring BBCode</strong>: %1$s<br />» %2$s',

'LOG_BOT_ADDED' => '<strong>New bot added</strong><br />» %s',
'LOG_BOT_DELETE' => '<strong>Deleted bot</strong><br />» %s',
Expand Down
43 changes: 30 additions & 13 deletions phpBB/phpbb/textformatter/s9e/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class factory implements \phpbb\textformatter\cache_interface
*/
protected $dispatcher;

/**
* @var \phpbb\log\log_interface
*/
protected $log;

/**
* Constructor
*
Expand All @@ -139,11 +144,12 @@ class factory implements \phpbb\textformatter\cache_interface
* @param \phpbb\event\dispatcher_interface $dispatcher
* @param \phpbb\config\config $config
* @param \phpbb\textformatter\s9e\link_helper $link_helper
* @param \phpbb\log\log_interface $log
* @param string $cache_dir Path to the cache dir
* @param string $cache_key_parser Cache key used for the parser
* @param string $cache_key_renderer Cache key used for the renderer
*/
public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\config\config $config, \phpbb\textformatter\s9e\link_helper $link_helper, $cache_dir, $cache_key_parser, $cache_key_renderer)
public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\config\config $config, \phpbb\textformatter\s9e\link_helper $link_helper, \phpbb\log\log_interface $log, $cache_dir, $cache_key_parser, $cache_key_renderer)
{
$this->link_helper = $link_helper;
$this->cache = $cache;
Expand All @@ -153,6 +159,7 @@ public function __construct(\phpbb\textformatter\data_access $data_access, \phpb
$this->config = $config;
$this->data_access = $data_access;
$this->dispatcher = $dispatcher;
$this->log = $log;
}

/**
Expand Down Expand Up @@ -272,7 +279,7 @@ public function get_configurator()
// Add default BBCodes
foreach ($this->get_default_bbcodes($configurator) as $bbcode)
{
$configurator->BBCodes->addCustom($bbcode['usage'], new UnsafeTemplate($bbcode['template']));
$this->add_bbcode($configurator, $bbcode['usage'], $bbcode['template']);
}
if (isset($configurator->tags['QUOTE']))
{
Expand All @@ -299,17 +306,7 @@ function ($m)
},
$row['bbcode_tpl']
);

try
{
$configurator->BBCodes->addCustom($row['bbcode_match'], new UnsafeTemplate($tpl));
}
catch (\Exception $e)
{
/**
* @todo log an error?
*/
}
$this->add_bbcode($configurator, $row['bbcode_match'], $tpl);
}

// Load smilies
Expand Down Expand Up @@ -418,6 +415,26 @@ public function regenerate()
return array('parser' => $parser, 'renderer' => $renderer);
}

/**
* Add a BBCode to given configurator
*
* @param Configurator $configurator
* @param string $usage
* @param string $template
* @return void
*/
protected function add_bbcode(Configurator $configurator, $usage, $template)
{
try
{
$configurator->BBCodes->addCustom($usage, new UnsafeTemplate($template));
}
catch (\Exception $e)
{
$this->log->add('critical', null, null, 'LOG_BBCODE_CONFIGURATION_ERROR', false, [$usage, $e->getMessage()]);
}
}

/**
* Configure the Autolink / Autoemail plugins used to linkify text
*
Expand Down
5 changes: 4 additions & 1 deletion tests/test_framework/phpbb_test_case_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,11 @@ public function set_s9e_services(ContainerInterface $container = null, $fixture
$request = new phpbb_mock_request;
}

// Get a log interface
$log = ($container->has('log')) ? $container->get('log') : $this->test_case->getMockBuilder('phpbb\\log\\log_interface')->getMock();

// Create and register the text_formatter.s9e.factory service
$factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $config, new \phpbb\textformatter\s9e\link_helper, $cache_dir, $cache_key_parser, $cache_key_renderer);
$factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $config, new \phpbb\textformatter\s9e\link_helper, $log, $cache_dir, $cache_key_parser, $cache_key_renderer);
$container->set('text_formatter.s9e.factory', $factory);

// Create a user if none was provided, and add the common lang strings
Expand Down
18 changes: 18 additions & 0 deletions tests/text_formatter/s9e/factory_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function get_factory($styles_path = null)
$this->dispatcher,
new \phpbb\config\config(array('allowed_schemes_links' => 'http,https,ftp')),
new \phpbb\textformatter\s9e\link_helper,
$this->getMockBuilder('phpbb\\log\\log_interface')->getMock(),
$this->get_cache_dir(),
'_foo_parser',
'_foo_renderer'
Expand Down Expand Up @@ -263,6 +264,23 @@ public function test_unsafe_default_bbcodes()
$this->assertSame($expected, $renderer->render($parser->parse($original)));
}

/**
* @testdox Logs malformed BBCodes
*/
public function test_malformed_bbcodes()
{
$log = $this->getMockBuilder('phpbb\\log\\log_interface')->getMock();
$log->expects($this->once())
->method('add')
->with('critical', null, null, 'LOG_BBCODE_CONFIGURATION_ERROR', false, ['[x !x]{TEXT}[/x]', 'Cannot interpret the BBCode definition']);

$container = new phpbb_mock_container_builder;
$container->set('log', $log);

$fixture = __DIR__ . '/fixtures/malformed_bbcode.xml';
$this->get_test_case_helpers()->set_s9e_services($container, $fixture);
}

/**
* @testdox get_configurator() triggers events before and after configuration
*/
Expand Down
28 changes: 28 additions & 0 deletions tests/text_formatter/s9e/fixtures/malformed_bbcode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_bbcodes">
<column>bbcode_id</column>
<column>bbcode_tag</column>
<column>bbcode_helpline</column>
<column>display_on_posting</column>
<column>bbcode_match</column>
<column>bbcode_tpl</column>
<column>first_pass_match</column>
<column>first_pass_replace</column>
<column>second_pass_match</column>
<column>second_pass_replace</column>

<row>
<value>13</value>
<value>x</value>
<value></value>
<value>1</value>
<value>[x !x]{TEXT}[/x]</value>
<value>...</value>
<value/>
<value/>
<value/>
<value/>
</row>
</table>
</dataset>

0 comments on commit a24a8a6

Please sign in to comment.