From 7fd916a81e2983a32f336d9ef1c6a876b9d287a1 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 16 Oct 2023 23:55:47 +0900 Subject: [PATCH] Fix miscellaneous issues with template parser v2 --- .../parsers/template/TemplateParser_v2.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/common/framework/parsers/template/TemplateParser_v2.php b/common/framework/parsers/template/TemplateParser_v2.php index 14918fb45..0bd234088 100644 --- a/common/framework/parsers/template/TemplateParser_v2.php +++ b/common/framework/parsers/template/TemplateParser_v2.php @@ -57,7 +57,7 @@ class TemplateParser_v2 ], 'once' => [ "if (!isset(\$GLOBALS['tplv2_once']['%uniq'])):", - "endif; \$GLOBALS['tplv2_once']['%uniq'] = true;", + "\$GLOBALS['tplv2_once']['%uniq'] = true; endif;", ], 'isset' => ['if (isset(%s)):', 'endif;'], 'unset' => ['if (!isset(%s)):', 'endif;'], @@ -175,12 +175,12 @@ class TemplateParser_v2 $basepath = \RX_BASEURL . $this->template->relative_dirname; // Convert all src and srcset attributes. - $regexp = '#(<(?:img|audio|video|script|input|source|link)\s[^>]*)(src|srcset)="([^"]+)"#'; + $regexp = '#(<(?:img|audio|video|script|input|source|link)\s[^>]*)(src|srcset|poster)="([^"]+)"#'; return preg_replace_callback($regexp, function($match) use ($basepath) { - if ($match[2] === 'src') + if ($match[2] !== 'srcset') { $src = trim($match[3]); - return $match[1] . sprintf('src="%s"', self::_isRelativePath($src) ? self::_convertRelativePath($src, $basepath) : $src); + return $match[1] . sprintf('%s="%s"', $match[2], self::_isRelativePath($src) ? self::_convertRelativePath($src, $basepath) : $src); } else { @@ -234,7 +234,7 @@ class TemplateParser_v2 protected function _convertVerbatimSections(string $content): string { $content = preg_replace_callback('#(@verbatim)(.+?)(@endverbatim)#s', function($match) { - return preg_replace(['#(?|[\x09\x20]*$)#sm'; + $regexp = '#(?:^[\x09\x20]*||[\x09\x20]*$)#sm'; $content = preg_replace_callback($regexp, function($match) { // Collect the necessary information. @@ -755,7 +759,7 @@ class TemplateParser_v2 } else { - return sprintf('', $args); + return sprintf('config->context === \'JS\' ? escape_js(lang(%s)) : lang(%s); ?>', $args, $args); } }, $content); @@ -1034,7 +1038,7 @@ class TemplateParser_v2 // Replace all other variables with Context attributes. $content = preg_replace_callback('#(?|\')\$([a-zA-Z_][a-zA-Z0-9_]*)#', function($match) { - if (preg_match('/^(?:GLOBALS|_SERVER|_COOKIE|_ENV|_GET|_POST|_REQUEST|_SESSION|__Context|this)$/', $match[1])) + if (preg_match('/^(?:GLOBALS|_SERVER|_COOKIE|_ENV|_GET|_POST|_REQUEST|_SESSION|__Context|this|loop)$/', $match[1])) { return '$' . $match[1]; }