mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Make ShortcodeParser obey error_behavior in attribute scope
This commit is contained in:
parent
1ee01c39d4
commit
7afcd64418
@ -332,7 +332,21 @@ class ShortcodeParser {
|
|||||||
|
|
||||||
if($tags) {
|
if($tags) {
|
||||||
$node->nodeValue = $this->replaceTagsWithText($node->nodeValue, $tags, function($idx, $tag) use ($parser){
|
$node->nodeValue = $this->replaceTagsWithText($node->nodeValue, $tags, function($idx, $tag) use ($parser){
|
||||||
return $parser->callShortcode($tag['open'], $tag['attrs'], $tag['content']);
|
$content = $parser->callShortcode($tag['open'], $tag['attrs'], $tag['content']);
|
||||||
|
|
||||||
|
if ($content === false) {
|
||||||
|
if(ShortcodeParser::$error_behavior == ShortcodeParser::ERROR) {
|
||||||
|
user_error('Unknown shortcode tag '.$tag['open'], E_USER_ERRROR);
|
||||||
|
}
|
||||||
|
else if(ShortcodeParser::$error_behavior == ShortcodeParser::STRIP) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $tag['text'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,18 +19,26 @@ class ShortcodeParserTest extends SapphireTest {
|
|||||||
*/
|
*/
|
||||||
public function testNotRegisteredShortcode() {
|
public function testNotRegisteredShortcode() {
|
||||||
ShortcodeParser::$error_behavior = ShortcodeParser::STRIP;
|
ShortcodeParser::$error_behavior = ShortcodeParser::STRIP;
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'',
|
'',
|
||||||
$this->parser->parse('[not_shortcode]')
|
$this->parser->parse('[not_shortcode]')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'<img class="">',
|
||||||
|
$this->parser->parse('<img class="[not_shortcode]">')
|
||||||
|
);
|
||||||
|
|
||||||
ShortcodeParser::$error_behavior = ShortcodeParser::WARN;
|
ShortcodeParser::$error_behavior = ShortcodeParser::WARN;
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'<strong class="warning">[not_shortcode]</strong>',
|
'<strong class="warning">[not_shortcode]</strong>',
|
||||||
$this->parser->parse('[not_shortcode]')
|
$this->parser->parse('[not_shortcode]')
|
||||||
);
|
);
|
||||||
|
|
||||||
ShortcodeParser::$error_behavior = ShortcodeParser::LEAVE;
|
ShortcodeParser::$error_behavior = ShortcodeParser::LEAVE;
|
||||||
|
|
||||||
$this->assertEquals('[not_shortcode]',
|
$this->assertEquals('[not_shortcode]',
|
||||||
$this->parser->parse('[not_shortcode]'));
|
$this->parser->parse('[not_shortcode]'));
|
||||||
$this->assertEquals('[not_shortcode /]',
|
$this->assertEquals('[not_shortcode /]',
|
||||||
@ -41,6 +49,11 @@ class ShortcodeParserTest extends SapphireTest {
|
|||||||
$this->parser->parse('[not_shortcode]a[/not_shortcode]'));
|
$this->parser->parse('[not_shortcode]a[/not_shortcode]'));
|
||||||
$this->assertEquals('[/not_shortcode]',
|
$this->assertEquals('[/not_shortcode]',
|
||||||
$this->parser->parse('[/not_shortcode]'));
|
$this->parser->parse('[/not_shortcode]'));
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'<img class="[not_shortcode]">',
|
||||||
|
$this->parser->parse('<img class="[not_shortcode]">')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleTag() {
|
public function testSimpleTag() {
|
||||||
|
Loading…
Reference in New Issue
Block a user