diff --git a/common/framework/Template.php b/common/framework/Template.php index 8234e13d6..7495edd33 100644 --- a/common/framework/Template.php +++ b/common/framework/Template.php @@ -59,6 +59,7 @@ class Template protected static $_mtime; protected static $_delay_compile; protected static $_json_options; + protected static $_json_options2; /** * Provided for compatibility with old TemplateHandler. @@ -100,6 +101,10 @@ class Template { self::$_json_options = \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_UNESCAPED_UNICODE; } + if (self::$_json_options2 === null) + { + self::$_json_options2 = \JSON_HEX_TAG | \JSON_HEX_QUOT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES; + } // If paths were provided, initialize immediately. if ($dirname && $filename) diff --git a/common/framework/parsers/template/TemplateParser_v2.php b/common/framework/parsers/template/TemplateParser_v2.php index be1861810..4b32977d7 100644 --- a/common/framework/parsers/template/TemplateParser_v2.php +++ b/common/framework/parsers/template/TemplateParser_v2.php @@ -724,7 +724,7 @@ class TemplateParser_v2 { case 'json': return sprintf('config->context === \'JS\' ? ' . - 'json_encode(%s, self::$_json_options) : ' . + 'json_encode(%s, self::$_json_options2) : ' . 'htmlspecialchars(json_encode(%s, self::$_json_options), \ENT_QUOTES, \'UTF-8\', false); ?>', $args, $args); case 'lang': return sprintf('config->context === \'JS\' ? escape_js($this->_v2_lang(%s)) : $this->_v2_lang(%s); ?>', $args, $args); diff --git a/tests/_data/template/v2example.compiled.html b/tests/_data/template/v2example.compiled.html index d4e395ea7..d4742e251 100644 --- a/tests/_data/template/v2example.compiled.html +++ b/tests/_data/template/v2example.compiled.html @@ -62,5 +62,5 @@ diff --git a/tests/unit/framework/parsers/TemplateParserV2Test.php b/tests/unit/framework/parsers/TemplateParserV2Test.php index 5ea0a40f9..847f655b3 100644 --- a/tests/unit/framework/parsers/TemplateParserV2Test.php +++ b/tests/unit/framework/parsers/TemplateParserV2Test.php @@ -919,7 +919,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit $source = '@json($var)'; $target = implode('', [ 'config->context === \'JS\' ? ', - 'json_encode($__Context->var, self::$_json_options) : ', + 'json_encode($__Context->var, self::$_json_options2) : ', 'htmlspecialchars(json_encode($__Context->var, self::$_json_options), \ENT_QUOTES, \'UTF-8\', false); ?>', ]); $this->assertEquals($target, $this->_parse($source)); @@ -928,7 +928,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit $source = '@json(["foo" => 1, "bar" => 2])'; $target = implode('', [ 'config->context === \'JS\' ? ', - 'json_encode(["foo" => 1, "bar" => 2], self::$_json_options) : ', + 'json_encode(["foo" => 1, "bar" => 2], self::$_json_options2) : ', 'htmlspecialchars(json_encode(["foo" => 1, "bar" => 2], self::$_json_options), \ENT_QUOTES, \'UTF-8\', false); ?>', ]); $this->assertEquals($target, $this->_parse($source));