Remove UTF-8 BOM and CRLF in templates when compiling them

This commit is contained in:
Kijin Sung 2023-09-05 01:05:53 +09:00
parent 55d3dd047c
commit a50041007d
2 changed files with 4 additions and 1 deletions

View file

@ -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);

View file

@ -263,7 +263,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
'?><input foo="bar" /> <?php if($__Context->foo->bar ?? false){ ?><img alt="alt" src="' . $this->baseurl . 'tests/unit/classes/common/mobile.gif" /><?php } ?>'
),
array(
'<input foo="bar" />' . "\n" . '<input foo="bar" /> <img cond="$foo->bar" alt="alt" src="../common/mobile.gif" />',
'<input foo="bar" />' . "\r\n" . '<input foo="bar" /> <img cond="$foo->bar" alt="alt" src="../common/mobile.gif" />',
'?><input foo="bar" />' . "\n" . '<input foo="bar" /> <?php if($__Context->foo->bar ?? false){ ?><img alt="alt" src="' . $this->baseurl . 'tests/unit/classes/common/mobile.gif" /><?php } ?>'
),
array(