From 66436c573ee8381d99688e7c9a2afb1d9feefe85 Mon Sep 17 00:00:00 2001 From: Krzysztof Pisz Date: Tue, 15 Apr 2025 20:20:42 +0200 Subject: [PATCH] Improve comment parsing for `{*}` to align with IDE syntax highlighting and legacy behavior - Adjusted TemplateLexer to ensure `{*}` properly opens comments and ends only on valid `*}` - Improved consistency with IDEs like PhpStorm and VS Code - Simplified upgrades for projects migrating from Smarty v2 by preserving familiar comment handling - Added new test case --- src/Lexer/TemplateLexer.php | 2 +- tests/UnitTests/TemplateSource/Comments/CommentsTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Lexer/TemplateLexer.php b/src/Lexer/TemplateLexer.php index 2e7f33055..08d14ab4e 100644 --- a/src/Lexer/TemplateLexer.php +++ b/src/Lexer/TemplateLexer.php @@ -381,7 +381,7 @@ public function yy_r1_2() { $to = $this->dataLength; - preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter+2); if (isset($match[0][1])) { $to = $match[0][1] + strlen($match[0][0]); } else { diff --git a/tests/UnitTests/TemplateSource/Comments/CommentsTest.php b/tests/UnitTests/TemplateSource/Comments/CommentsTest.php index 443ac39e6..e7e130625 100644 --- a/tests/UnitTests/TemplateSource/Comments/CommentsTest.php +++ b/tests/UnitTests/TemplateSource/Comments/CommentsTest.php @@ -69,6 +69,7 @@ public function dataTestComments() array("=\na\n{* comment 1 *}\n {* comment 2 *}\n{* comment 3 *}\nb\n=", "=\na\n b\n=", 'T12', $i++), array("=\na\n{* comment 1 *}\n{* comment 2 *} \n{* comment 3 *}\nb\n=", "=\na\n \nb\n=", 'T13', $i++), array("=\na\n{* comment 1 *}\n {* comment 2 *} \n{* comment 3 *}\nb\n=", "=\na\n \nb\n=", 'T14', $i++), + array("K{*} comment 1 *}L{*} comment 2 {*}", "KL", 'T15', $i++), ); }