Fix #2272 unintended conversion of v1 echo statements inside verbatim section of v2 template

This commit is contained in:
Kijin Sung 2024-01-16 21:43:38 +09:00
parent a0af57139e
commit ee9a1a2b20
2 changed files with 11 additions and 2 deletions

View file

@ -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(['#(?<!@)\{\{#', '#(?<!@)@([a-z]+)#', '#\$#'], ['@{{', '@@$1', '&#x1B;&#x24;'], $match[2]);
$conversions = [
'#(?<!\{)\{(?!\s)([^{}]+?)\}#' => '&#x1B;&#x7B;$1&#x1B;&#x7D;',
'#(?<!@)\{\{#' => '@{{',
'#(?<!@)@([a-z]+)#' => '@@$1',
'#\$#' => '&#x1B;&#x24;',
];
$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;
}

View file

@ -1015,6 +1015,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit
'@verbatim',
'@if (true)',
'<p>{{ $foobar }}</p>',
'<p>{$foobar}</p>',
'@endif',
'@endverbatim',
]);
@ -1022,6 +1023,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit
'',
'@if (true)',
'<p>{{ $foobar }}</p>',
'<p>{$foobar}</p>',
'@endif',
'',
]);