diff --git a/parsers/ShortcodeParser.php b/parsers/ShortcodeParser.php
index 79ea1a52d..6123f9162 100644
--- a/parsers/ShortcodeParser.php
+++ b/parsers/ShortcodeParser.php
@@ -332,7 +332,21 @@ class ShortcodeParser {
if($tags) {
$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;
});
}
}
diff --git a/tests/parsers/ShortcodeParserTest.php b/tests/parsers/ShortcodeParserTest.php
index 3f571b484..d90b870bc 100644
--- a/tests/parsers/ShortcodeParserTest.php
+++ b/tests/parsers/ShortcodeParserTest.php
@@ -19,18 +19,26 @@ class ShortcodeParserTest extends SapphireTest {
*/
public function testNotRegisteredShortcode() {
ShortcodeParser::$error_behavior = ShortcodeParser::STRIP;
+
$this->assertEquals(
'',
$this->parser->parse('[not_shortcode]')
);
+ $this->assertEquals(
+ '',
+ $this->parser->parse('')
+ );
+
ShortcodeParser::$error_behavior = ShortcodeParser::WARN;
+
$this->assertEquals(
'[not_shortcode]',
$this->parser->parse('[not_shortcode]')
);
ShortcodeParser::$error_behavior = ShortcodeParser::LEAVE;
+
$this->assertEquals('[not_shortcode]',
$this->parser->parse('[not_shortcode]'));
$this->assertEquals('[not_shortcode /]',
@@ -41,6 +49,11 @@ class ShortcodeParserTest extends SapphireTest {
$this->parser->parse('[not_shortcode]a[/not_shortcode]'));
$this->assertEquals('[/not_shortcode]',
$this->parser->parse('[/not_shortcode]'));
+
+ $this->assertEquals(
+ '',
+ $this->parser->parse('')
+ );
}
public function testSimpleTag() {