From ee9a1a2b20c68969de418e3f9263978a41b1ae74 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 16 Jan 2024 21:43:38 +0900 Subject: [PATCH] Fix #2272 unintended conversion of v1 echo statements inside verbatim section of v2 template --- .../framework/parsers/template/TemplateParser_v2.php | 11 +++++++++-- tests/unit/framework/parsers/TemplateParserV2Test.php | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/framework/parsers/template/TemplateParser_v2.php b/common/framework/parsers/template/TemplateParser_v2.php index 12593e223..be1861810 100644 --- a/common/framework/parsers/template/TemplateParser_v2.php +++ b/common/framework/parsers/template/TemplateParser_v2.php @@ -285,8 +285,15 @@ class TemplateParser_v2 */ protected function _convertVerbatimSections(string $content): string { - $content = preg_replace_callback('#(@verbatim)\b(.+?)(@endverbatim)\b#s', function($match) { - return preg_replace(['#(? '{$1}', + '#(? '@{{', + '#(? '@@$1', + '#\$#' => '$', + ]; + + $content = preg_replace_callback('#(@verbatim)\b(.+?)(@endverbatim)\b#s', function($match) use($conversions) { + return preg_replace(array_keys($conversions), array_values($conversions), $match[2]); }, $content); return $content; } diff --git a/tests/unit/framework/parsers/TemplateParserV2Test.php b/tests/unit/framework/parsers/TemplateParserV2Test.php index 72bcda4ee..5ea0a40f9 100644 --- a/tests/unit/framework/parsers/TemplateParserV2Test.php +++ b/tests/unit/framework/parsers/TemplateParserV2Test.php @@ -1015,6 +1015,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit '@verbatim', '@if (true)', '

{{ $foobar }}

', + '

{$foobar}

', '@endif', '@endverbatim', ]); @@ -1022,6 +1023,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit '', '@if (true)', '

{{ $foobar }}

', + '

{$foobar}

', '@endif', '', ]);