From a50041007d2b2be3ccc3855be2bc0675d4872cf9 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 5 Sep 2023 01:05:53 +0900 Subject: [PATCH] Remove UTF-8 BOM and CRLF in templates when compiling them --- classes/template/TemplateHandler.class.php | 3 +++ tests/unit/classes/TemplateHandlerTest.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php index 123fcdc6b..97030c8fb 100644 --- a/classes/template/TemplateHandler.class.php +++ b/classes/template/TemplateHandler.class.php @@ -286,6 +286,9 @@ class TemplateHandler // detect existence of autoescape config $this->config->autoescape = (strpos($buff, ' autoescape="') === false) ? null : false; + // remove UTF-8 BOM and convert CRLF to LF + $buff = preg_replace(['/^\xEF\xBB\xBF/', '/\r\n/'], ['', "\n"], $buff); + // replace comments $buff = preg_replace('@@s', '', $buff); diff --git a/tests/unit/classes/TemplateHandlerTest.php b/tests/unit/classes/TemplateHandlerTest.php index aeaa5a1c0..399ca5518 100644 --- a/tests/unit/classes/TemplateHandlerTest.php +++ b/tests/unit/classes/TemplateHandlerTest.php @@ -263,7 +263,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test '?> foo->bar ?? false){ ?>alt' ), array( - '' . "\n" . ' alt', + '' . "\r\n" . ' alt', '?>' . "\n" . ' foo->bar ?? false){ ?>alt' ), array(