From d83e3ac44ddb1faed13a531425d5babf676d9711 Mon Sep 17 00:00:00 2001 From: Russell Michell Date: Fri, 6 Sep 2013 10:59:22 +1200 Subject: [PATCH] FIX: Fixes #2382 - Errors are thrown in front-end should the parser encounter a shortcode with a value of '0' - Added test --- parsers/ShortcodeParser.php | 4 ++-- tests/parsers/ShortcodeParserTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/parsers/ShortcodeParser.php b/parsers/ShortcodeParser.php index 8388873e78e..f1b4da7c554 100644 --- a/parsers/ShortcodeParser.php +++ b/parsers/ShortcodeParser.php @@ -218,9 +218,9 @@ protected function extractTags($content) { preg_match_all(self::attrrx(), $match['attrs'][0], $attrmatches, PREG_SET_ORDER); foreach ($attrmatches as $attr) { - list($whole, $name, $value) = array_values(array_filter($attr)); + list($whole, $name, $value) = array_values(array_filter($attr, 'strlen')); $attrs[$name] = $value; - } + } } // And store the indexes, tag details, etc diff --git a/tests/parsers/ShortcodeParserTest.php b/tests/parsers/ShortcodeParserTest.php index a87caff8574..eb8afa05a7b 100644 --- a/tests/parsers/ShortcodeParserTest.php +++ b/tests/parsers/ShortcodeParserTest.php @@ -88,6 +88,18 @@ public function testOneArgument() { } } + public function testOneFalseishArgumentWhereIsZero() { + $tests = array ( + '[test_shortcode foo="0"]', "[test_shortcode foo='0']", + '[test_shortcode foo=0]' + ); + + foreach($tests as $test) { + $this->parser->parse($test); + $this->assertEquals(array('foo' => 0), $this->arguments, $test); + } + } + public function testMultipleArguments() { $this->parser->parse('[test_shortcode foo = "bar",bar=\'foo\', baz="buz"]');