From d9e7e2eb4effcaddb2facda6445c5aa40d427c7e 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 28af2fe682..38abaf52df 100644 --- a/src/Latte/Compiler/PhpWriter.php +++ b/src/Latte/Compiler/PhpWriter.php @@ -274,9 +274,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 087db559e4..8f5d8e3849 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 d3bce9a585..3c4eb5b019 100644 --- a/tests/Latte/PhpWriter.formatArgs().phpt +++ b/tests/Latte/PhpWriter.formatArgs().phpt @@ -87,10 +87,11 @@ 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('$var = match(7) {8 => true, default => false,}', formatArgs('$var = match(7) {8 => true, default => false,}')); + Assert::same("a b", formatArgs('a/**/b')); });