diff --git a/common/framework/parsers/template/TemplateParser_v2.php b/common/framework/parsers/template/TemplateParser_v2.php index 108075f27..24cf085fc 100644 --- a/common/framework/parsers/template/TemplateParser_v2.php +++ b/common/framework/parsers/template/TemplateParser_v2.php @@ -784,7 +784,9 @@ class TemplateParser_v2 $escape_option = $filter; break; case 'escapejs': + case 'js': $str = "escape_js({$str})"; + $escape_option = 'noescape'; break; case 'json': $str = "json_encode({$str}, \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES)"; diff --git a/modules/admin/controllers/maintenance/Cleanup.php b/modules/admin/controllers/maintenance/Cleanup.php index 87a0422c1..26595408f 100644 --- a/modules/admin/controllers/maintenance/Cleanup.php +++ b/modules/admin/controllers/maintenance/Cleanup.php @@ -361,6 +361,8 @@ class Cleanup extends Base 'modules/spamfilter/spamfilter.lib.php' => 'deleted', 'modules/spamfilter/ruleset/' => 'deleted', 'phpDoc/' => 'deleted:xe', + 'tests/unit/classes/template/' => 'deleted', + 'tests/unit/classes/TemplateHandlerTest.php' => 'deleted', 'tools/dbxml_validator/' => 'deleted:xe', 'tools/korea_ip_ranges/' => 'deleted', 'tools/phpDoc/' => 'deleted', diff --git a/tests/unit/classes/template/css/style.css b/tests/_data/template/css/style.css similarity index 100% rename from tests/unit/classes/template/css/style.css rename to tests/_data/template/css/style.css diff --git a/tests/unit/classes/template/sample.html b/tests/_data/template/sample.html similarity index 100% rename from tests/unit/classes/template/sample.html rename to tests/_data/template/sample.html diff --git a/tests/unit/classes/TemplateHandlerTest.php b/tests/unit/framework/parsers/TemplateParserV1Test.php similarity index 90% rename from tests/unit/classes/TemplateHandlerTest.php rename to tests/unit/framework/parsers/TemplateParserV1Test.php index c0d0151a2..03b75336e 100644 --- a/tests/unit/classes/TemplateHandlerTest.php +++ b/tests/unit/framework/parsers/TemplateParserV1Test.php @@ -1,13 +1,13 @@ baseurl = '/' . basename(dirname(dirname(dirname(__DIR__)))) . '/'; + $this->baseurl = '/' . basename(dirname(dirname(dirname(dirname(__DIR__))))) . '/'; } public function testParse() @@ -101,42 +101,42 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // #include array( '
This is another dummy
', - '?>compile(\'tests/unit/classes/template\',\'sample.html\') ?>
This is another dummy
' + '?>compile(\'tests/_data/template\',\'sample.html\') ?>
This is another dummy
' ), // array( '
This is another dummy
', - '?>compile(\'tests/unit/classes\',\'sample.html\') ?>
This is another dummy
' + '?>compile(\'tests/_data\',\'sample.html\') ?>
This is another dummy
' ), // array( - '', + '', '?>' ), // array( '', - '?>' + '?>' ), // array( '', - '?>' + '?>' ), // array( - '', + '', '?>compile(); ?>' ), // array( '', - '?>' + '?>' ), // array( '', - '?>' + '?>' ), // comment array( @@ -151,11 +151,11 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // relative path1 array( '', - '?>' + '?>' ), // relative path2 array( - '', + '', '?>' ), // error case @@ -211,12 +211,12 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // issue 512 - ignores array( '
{$lang->sl_show_topimgtext}
', - '?>
sl_show_topimgtext ?>
' + '?>
lang->sl_show_topimgtext ?? \'\' ?>
' ), // issue 584 array( 'mobile', - 'if($__Context->oBodex->display_extra_images[\'mobile\'] && $__Context->arr_extra && $__Context->arr_extra->bodex->mobile){ ?>mobile' + 'if($__Context->oBodex->display_extra_images[\'mobile\'] && $__Context->arr_extra && $__Context->arr_extra->bodex->mobile){ ?>mobile' ), // issue 831 array( @@ -226,7 +226,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // issue 746 array( '', - '?>' + '?>' ), // issue 696 array( @@ -236,35 +236,35 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // https://github.com/xpressengine/xe-core/issues/1510 array( '', - 'if($__Context->foo->bar ?? false){ ?>' + 'if($__Context->foo->bar ?? false){ ?>' ), // https://github.com/xpressengine/xe-core/issues/1510 array( 'a!@#$%^&*()_-=[]{}?/', - 'if($__Context->foo->bar > 100){ ?>a!@#$%^&*()_-=[]{}?/' + 'if($__Context->foo->bar > 100){ ?>a!@#$%^&*()_-=[]{}?/' ), // https://github.com/xpressengine/xe-core/issues/1510 array( '', - 'if($__Context->foo->bar ?? false){ ?>' + 'if($__Context->foo->bar ?? false){ ?>' ), // https://github.com/xpressengine/xe-core/issues/1510 array( '', - 'if(!$__Context->module_info->title){ ?>' + 'if(!$__Context->module_info->title){ ?>' ), // https://github.com/xpressengine/xe-core/issues/1510 array( '', - 'if($__Context->mi->title ?? false){ ?>mi->use){ ?> class="tmp_class" src="' . $this->baseurl . 'tests/unit/classes/img/common/blank.gif" />' + 'if($__Context->mi->title ?? false){ ?>mi->use){ ?> class="tmp_class" src="' . $this->baseurl . 'tests/_data/img/common/blank.gif" />' ), array( ' alt', - '?> foo->bar ?? false){ ?>alt' + '?> foo->bar ?? false){ ?>alt' ), array( '' . "\r\n" . ' alt', - '?>' . "\n" . ' foo->bar ?? false){ ?>alt' + '?>' . "\n" . ' foo->bar ?? false){ ?>alt' ), array( 'asf ', @@ -272,11 +272,11 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test ), array( '', - '?>' + '?>' ), array( 'asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf', - '?>asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf' + '?>asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf' ), array( 'asdf src="../img/img.gif" asdf', @@ -289,7 +289,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // srcset (PR #1544) array( 'this is a test image.', - '?>this is a test image.' + '?>this is a test image.' ), // Rhymix improvements (PR #604) array( @@ -505,7 +505,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test foreach ($tests as $test) { $tmpl = new TemplateHandlerWrapper; - $tmpl->init(__DIR__ . '/template', 'no_file.html'); + $tmpl->init('./tests/_data/template', 'no_file.html'); $result = $tmpl->parse($test[0]); $between = str_starts_with($test[1], '?>') ? '' : ' '; $this->assertEquals($this->prefix . $between . $test[1], $result); @@ -515,7 +515,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test public function testParseNoContent() { $tmpl = new TemplateHandlerWrapper; - $tmpl->init(__DIR__ . '/template', 'no_file.html'); + $tmpl->init('./tests/_data/template', 'no_file.html'); $result = $tmpl->parse(null); $this->assertEquals('', $result); @@ -524,7 +524,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test public function testCompileDirect() { $tmpl = TemplateHandler::getInstance(); - $result = $tmpl->compileDirect(__DIR__ . '/template', 'sample.html'); + $result = $tmpl->compileDirect('./tests/_data/template', 'sample.html'); $result = trim($result); $this->assertEquals($this->prefix . ' if($__Context->has_blog ?? false){ ?>Taggon\'s blog'.PHP_EOL.'', $result);