diff --git a/parsers/ShortcodeParser.php b/parsers/ShortcodeParser.php index 68b78fa91..95c1ae7ad 100644 --- a/parsers/ShortcodeParser.php +++ b/parsers/ShortcodeParser.php @@ -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); diff --git a/tests/parsers/ShortcodeParserTest.php b/tests/parsers/ShortcodeParserTest.php index 97b6aae91..f28d5bc27 100644 --- a/tests/parsers/ShortcodeParserTest.php +++ b/tests/parsers/ShortcodeParserTest.php @@ -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 { '', $this->parser->parse('') ); + + $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('
test
'); + } + // ----------------------------------------------------------------------------------------------------------------- /**