From cc3cec6c3467c0e7eb35c14ba7a6b35f3069827d Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 26 Nov 2021 23:39:22 +0100 Subject: [PATCH] PhpWriter::removeCommentsPass() replaces comment with space to prevent unwanted result ie. 'a/**/b' will not result to 'ab' --- src/Latte/Compiler/PhpWriter.php | 4 +--- tests/Latte/Compiler.special.phpt | 5 +++++ tests/Latte/PhpWriter.formatArgs().phpt | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Latte/Compiler/PhpWriter.php b/src/Latte/Compiler/PhpWriter.php index 129b0123b..a8cc43129 100644 --- a/src/Latte/Compiler/PhpWriter.php +++ b/src/Latte/Compiler/PhpWriter.php @@ -270,9 +270,7 @@ public function removeCommentsPass(MacroTokens $tokens): MacroTokens { $res = new MacroTokens; while ($tokens->nextToken()) { - if (!$tokens->isCurrent($tokens::T_COMMENT)) { - $res->append($tokens->currentToken()); - } + $res->append($tokens->isCurrent($tokens::T_COMMENT) ? ' ' : $tokens->currentToken()); } return $res; } diff --git a/tests/Latte/Compiler.special.phpt b/tests/Latte/Compiler.special.phpt index 087db559e..8f5d8e384 100644 --- a/tests/Latte/Compiler.special.phpt +++ b/tests/Latte/Compiler.special.phpt @@ -33,3 +33,8 @@ Assert::match( '%A%echo LR\Filters::escapeHtmlText(test(fn () => 1))%A%', $latte->compile('{test(fn () => 1)}') ); + +Assert::match( + "%A%('foo')/ **/('bar')%A%", + $latte->compile('{(foo)//**/**/(bar)}') +); diff --git a/tests/Latte/PhpWriter.formatArgs().phpt b/tests/Latte/PhpWriter.formatArgs().phpt index 7a895f505..6b29ca5b3 100644 --- a/tests/Latte/PhpWriter.formatArgs().phpt +++ b/tests/Latte/PhpWriter.formatArgs().phpt @@ -87,9 +87,10 @@ test('special', function () { Assert::same("'symbol' => \$this->var, ", formatArgs('symbol => $this -> var, ')); Assert::same("'symbol' => \$this->VAR, ", formatArgs('symbol => $this -> VAR, ')); Assert::same("'symbol' => \$this->var", formatArgs('symbol => $this -> var')); - Assert::same("'symbol1' => 'value'", formatArgs('symbol1 => /*value,* /symbol2=>*/value/**/')); + Assert::same("'symbol1' => 'value' ", formatArgs('symbol1 => /*value,* /symbol2=>*/value/**/')); Assert::same('(array)', formatArgs('(array)')); Assert::same('func()[1]', formatArgs('func()[1]')); + Assert::same('a b', formatArgs('a/**/b')); });