diff --git a/_test/tests/inc/html_secedit_pattern.test.php b/_test/tests/inc/html_secedit_pattern.test.php new file mode 100644 index 0000000000000000000000000000000000000000..1c0107801463ff6627ee291ca4eacd366bc05473 --- /dev/null +++ b/_test/tests/inc/html_secedit_pattern.test.php @@ -0,0 +1,58 @@ +<?php + +class html_scedit_pattern_test extends DokuWikiTest { + + + public function dataProviderForTestSecEditPattern() { + return [ + [ + '<!-- EDIT5 SECTION "Plugins" "plugins" [1406-] -->', + [ + 'secid' => '5', + 'target' => 'SECTION', + 'name' => 'Plugins', + 'hid' => 'plugins', + 'range' => '1406-', + ], + 'basic section edit', + ], + [ + '<!-- EDIT10 TABLE "" "table4" [11908-14014] -->', + [ + 'secid' => '10', + 'target' => 'TABLE', + 'name' => '', + 'hid' => 'table4', + 'range' => '11908-14014', + ], + 'table edit' + ], + [ + '<!-- EDIT2 PLUGIN_DATA [27-432] -->', + [ + 'secid' => '2', + 'target' => 'PLUGIN_DATA', + 'name' => '', + 'hid' => '', + 'range' => '27-432', + ], + 'data plugin' + ], + ]; + } + + /** + * @dataProvider dataProviderForTestSecEditPattern + * + * @param $text + * @param $expectedMatches + * @param $msg + */ + public function testSecEditPattern($text, $expectedMatches, $msg) { + preg_match(SEC_EDIT_PATTERN, $text, $matches); + foreach ($expectedMatches as $key => $expected_value) { + $this->assertSame($expected_value, $matches[$key], $msg); + } + } + +} diff --git a/inc/html.php b/inc/html.php index d370d48b2a99663942d7a4e57ce75e9179031dfa..350c65f076f92349246ab0e3f7104d4fa3c9ab91 100644 --- a/inc/html.php +++ b/inc/html.php @@ -8,6 +8,10 @@ if(!defined('DOKU_INC')) die('meh.'); if(!defined('NL')) define('NL',"\n"); +if (!defined('SEC_EDIT_PATTERN')) { + define('SEC_EDIT_PATTERN', '#<!-- EDIT(?<secid>\d+) (?<target>[A-Z_]+) (?:"(?<name>[^"]*)" )?(?:"(?<hid>[^"]*)" )?\[(?<range>\d+-\d*)\] -->#'); +} + /** * Convenience function to quickly build a wikilink @@ -91,13 +95,11 @@ function html_denied() { function html_secedit($text,$show=true){ global $INFO; - $regexp = '#<!-- EDIT(?<secid>\d+) (?<target>[A-Z_]+) (?:"(?<name>[^"]*)" )?(?:"(?<hid>[^"]*)" )?\[(?<range>\d+-\d*)\] -->#'; - if(!$INFO['writable'] || !$show || $INFO['rev']){ - return preg_replace($regexp,'',$text); + return preg_replace(SEC_EDIT_PATTERN,'',$text); } - return preg_replace_callback($regexp, + return preg_replace_callback(SEC_EDIT_PATTERN, 'html_secedit_button', $text); }