From dd4d4fe9799123bd8be08b5808e180fadae2754f Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 17 Jun 2025 17:15:49 +0900 Subject: [PATCH] Treat pattern attribute of form elements as JS context in Template v2 --- common/framework/parsers/template/TemplateParser_v2.php | 2 +- tests/unit/framework/parsers/TemplateParserV2Test.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/framework/parsers/template/TemplateParser_v2.php b/common/framework/parsers/template/TemplateParser_v2.php index 501845a2a..399e45d97 100644 --- a/common/framework/parsers/template/TemplateParser_v2.php +++ b/common/framework/parsers/template/TemplateParser_v2.php @@ -185,7 +185,7 @@ class TemplateParser_v2 }, $content); // Inline scripts. - $content = preg_replace_callback('#(?<=\s)(href="javascript:|on[a-z]+=")([^"]*?)"#i', function($match) { + $content = preg_replace_callback('#(?<=\s)(href="javascript:|pattern="|on[a-z]+=")([^"]*?)"#i', function($match) { return $match[1] . 'config->context = \'JS\'; ?>' . $match[2] . 'config->context = \'HTML\'; ?>"'; }, $content); diff --git a/tests/unit/framework/parsers/TemplateParserV2Test.php b/tests/unit/framework/parsers/TemplateParserV2Test.php index ce6e68ab7..d220f4da9 100644 --- a/tests/unit/framework/parsers/TemplateParserV2Test.php +++ b/tests/unit/framework/parsers/TemplateParserV2Test.php @@ -265,6 +265,14 @@ class TemplateParserV2Test extends \Codeception\Test\Unit $target = '
Hello
'; $this->assertEquals($target, $this->_parse($source, true, false)); + // pattern attribute in tag + $source = ''; + $target = ''; + $this->assertEquals($target, $this->_parse($source, true, false)); + $source = ''; + $target = ''; + $this->assertEquals($target, $this->_parse($source, true, false)); + // '; $target = 'config->context = \'CSS\'; ?>> body { font-size: 16px; } config->context = \'HTML\'; ?>';