Add deprecation warnings if syntax like <--#include-->, <!--%import--> is used in template v2

This commit is contained in:
Kijin Sung 2023-10-23 14:17:30 +09:00
parent 6a2a2826ec
commit c42d059594
2 changed files with 15 additions and 0 deletions

View file

@ -932,6 +932,11 @@ class TemplateParser_v2
*/
protected function _addDeprecationMessages(string $content): string
{
// <!--#include-->, <!--%import-->, etc.
$content = preg_replace_callback('#<!--(\#include|%import|%unload|%load_js_plugin)\s?\(.+?-->#', function($match) {
return '<?php trigger_error("' . $match[1] . ' is not supported in template v2", \E_USER_WARNING); ?>';
}, $content);
// <block>
$content = preg_replace_callback('#<block(?=\s)#', function($match) {
return $match[0] . '<?php trigger_error("block element is not supported in template v2", \E_USER_WARNING); ?>';

View file

@ -1059,6 +1059,16 @@ class TemplateParserV2Test extends \Codeception\Test\Unit
public function testDeprecationMessages()
{
// <!--#include()-->
$source = '<!--#include("foo.html")-->';
$target = '<?php trigger_error("#include is not supported in template v2", \E_USER_WARNING); ?>';
$this->assertEquals($target, $this->_parse($source));
// <!--%import()-->
$source = '<!--%import("../foo/bar.js")-->';
$target = '<?php trigger_error("%import is not supported in template v2", \E_USER_WARNING); ?>';
$this->assertEquals($target, $this->_parse($source));
// <block> element
$source = '<block class="foobar">';
$target = '<block<?php trigger_error("block element is not supported in template v2", \E_USER_WARNING); ?> class="foobar">';