From f2fabab239c78f4bab23fbe13195c26b733b7701 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 16 Oct 2023 21:15:52 +0900 Subject: [PATCH] Fix conversion of paths relative to the Rhymix install directory --- .../parsers/template/TemplateParser_v2.php | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/common/framework/parsers/template/TemplateParser_v2.php b/common/framework/parsers/template/TemplateParser_v2.php index 7f2165dac..14918fb45 100644 --- a/common/framework/parsers/template/TemplateParser_v2.php +++ b/common/framework/parsers/template/TemplateParser_v2.php @@ -824,7 +824,7 @@ class TemplateParser_v2 if (preg_match('#^([a-z0-9_-]+):(.+)$#', $filter, $m)) { $filter = $m[1]; - $filter_option = $m[2]; + $filter_option = strtr($m[2], ['\|' => '|']); if (!preg_match('#^\$#', $filter_option) && !preg_match('#^([\'"]).*\1$#', $filter_option)) { $filter_option = "'" . escape_sqstr($filter_option) . "'"; @@ -838,7 +838,6 @@ class TemplateParser_v2 // Apply each filter. switch ($filter) { - case 'autocontext': case 'autoescape': case 'autolang': case 'escape': @@ -938,34 +937,6 @@ class TemplateParser_v2 } } - /** - * Convert variable scope. - * - * @param string $content - * @return string - */ - protected function _convertVariableScope(string $content): string - { - // Replace variables that need to be enclosed in curly braces, using temporary entities to prevent double-replacement. - $content = preg_replace_callback('#(?\$([a-zA-Z_][a-zA-Z0-9_]*)#', function($match) { - return '->' . self::_escapeCurly('{') . '$__Context->' . $match[1] . self::_escapeCurly('}'); - }, $content); - - // 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])) - { - return '$' . $match[1]; - } - else - { - return '$__Context->' . $match[1]; - } - }, $content); - - return $content; - } - /** * Postprocessing. * @@ -1026,7 +997,21 @@ class TemplateParser_v2 */ protected static function _convertRelativePath(string $path, string $basepath): string { - $path = preg_replace('#/\./#', '/', $basepath . $path); + // Path relative to the Rhymix installation directory? + if (preg_match('#^\^/?(\w.+)$#s', $path, $match)) + { + $path = \RX_BASEURL . $match[1]; + } + + // Other paths will be relative to the given basepath. + else + { + $path = preg_replace('#/\./#', '/', $basepath . $path); + } + + // Remove extra slashes and parent directory references. + $path = preg_replace('#\\\\#', '/', $path); + $path = preg_replace('#//#', '/', $path); while (($tmp = preg_replace('#/[^/]+/\.\./#', '/', $path)) !== $path) { $path = $tmp; @@ -1034,6 +1019,34 @@ class TemplateParser_v2 return $path; } + /** + * Convert variable scope. + * + * @param string $content + * @return string + */ + protected function _convertVariableScope(string $content): string + { + // Replace variables that need to be enclosed in curly braces, using temporary entities to prevent double-replacement. + $content = preg_replace_callback('#(?\$([a-zA-Z_][a-zA-Z0-9_]*)#', function($match) { + return '->' . self::_escapeCurly('{') . '$__Context->' . $match[1] . self::_escapeCurly('}'); + }, $content); + + // 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])) + { + return '$' . $match[1]; + } + else + { + return '$__Context->' . $match[1]; + } + }, $content); + + return $content; + } + /** * Get attributes of an HTML tag as an associative array. *