mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Check for shortcode tag before trying to parse shortcodes
This commit is contained in:
parent
2cdfe6cc21
commit
765f45eaf1
@ -537,6 +537,9 @@ class ShortcodeParser extends Object {
|
||||
// If no content, don't try and parse it
|
||||
if (!trim($content)) return $content;
|
||||
|
||||
// If no shortcode tag, don't try and parse it
|
||||
if (strpos($content, '[') === false) return $content;
|
||||
|
||||
// First we operate in text mode, replacing any shortcodes with marker elements so that later we can
|
||||
// use a proper DOM
|
||||
list($content, $tags) = $this->replaceElementTagsWithMarkers($content);
|
||||
|
@ -14,7 +14,13 @@ class ShortcodeParserTest extends SapphireTest {
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
||||
public function tearDown() {
|
||||
ShortcodeParser::get('test')->unregister('test_shortcode');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that valid short codes that have not been registered are not replaced.
|
||||
*/
|
||||
@ -240,6 +246,8 @@ class ShortcodeParserTest extends SapphireTest {
|
||||
'<script>this is 2</script>',
|
||||
$this->parser->parse('<script>[2]</script>')
|
||||
);
|
||||
|
||||
$this->parser->unregister('2');
|
||||
}
|
||||
|
||||
public function testExtraContext() {
|
||||
@ -250,6 +258,18 @@ class ShortcodeParserTest extends SapphireTest {
|
||||
$this->assertEquals($this->extra['element']->tagName, 'a');
|
||||
}
|
||||
|
||||
public function testNoParseAttemptIfNoCode() {
|
||||
$stub = $this->getMock('ShortcodeParser', array('replaceElementTagsWithMarkers'));
|
||||
$stub->register('test', function() {
|
||||
return '';
|
||||
});
|
||||
|
||||
$stub->expects($this->never())
|
||||
->method('replaceElementTagsWithMarkers')->will($this->returnValue(array('', '')));
|
||||
|
||||
$stub->parse('<p>test</p>');
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user