From 7e26f78b0339339f4270f5e886ca9fc335fa5386 Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Fri, 1 Feb 2019 10:44:39 +0100 Subject: [PATCH] fixed skipping shortcodes in RegularParser when bbCode or parameter value was string '0' which is falsy in PHP --- src/Parser/RegularParser.php | 4 ++-- tests/ParserTest.php | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Parser/RegularParser.php b/src/Parser/RegularParser.php index 8d799e0..061b6f8 100644 --- a/src/Parser/RegularParser.php +++ b/src/Parser/RegularParser.php @@ -200,9 +200,9 @@ private function value() return $this->match(self::TOKEN_DELIMITER, false) ? $value : false; } - if($tmp = $this->match(self::TOKEN_STRING, false)) { + if('' !== $tmp = $this->match(self::TOKEN_STRING, false)) { $value .= $tmp; - while($tmp = $this->match(self::TOKEN_STRING, false)) { + while('' !== $tmp = $this->match(self::TOKEN_STRING, false)) { $value .= $tmp; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 3080aae..50274ab 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -225,6 +225,10 @@ public function provideShortcodes() new ParsedShortcode(new Shortcode('y', array(), ' ] [] [ [z] [/#] [/z] [ [] ] [/] ', null), '[y] ] [] [ [z] [/#] [/z] [ [] ] [/] [/y]', 27), new ParsedShortcode(new Shortcode('z', array(), ' [ [/ [/] /] ] ', null), '[z] [ [/ [/] /] ] [/z]', 70), )), + // falsy string values + array($s, '[a=0 b=0]0[/a]', array( + new ParsedShortcode(new Shortcode('a', array('b' => '0'), '0', '0'), '[a=0 b=0]0[/a]', 0), + )), ); /** @@ -239,7 +243,7 @@ public function provideShortcodes() * * Tests cases from array above with identifiers in the array below must be skipped. */ - $wordpressSkip = array(3, 6, 16, 21, 22, 23, 25, 32, 33, 34, 46, 47, 49); + $wordpressSkip = array(3, 6, 16, 21, 22, 23, 25, 32, 33, 34, 46, 47, 49, 51); $result = array(); foreach($tests as $key => $test) { $syntax = array_shift($test);