Check for shortcode tag before trying to parse shortcodes

This commit is contained in:
Daniel Hensby 2016-06-30 15:59:55 +01:00
parent 2cdfe6cc21
commit 765f45eaf1
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 24 additions and 1 deletions

View File

@ -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);

View File

@ -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>');
}
// -----------------------------------------------------------------------------------------------------------------
/**