Skip to content

Commit cbc0086

Browse files
committed
Remove UTF-8 BOM
1 parent dffecbc commit cbc0086

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/Phug/Reader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ class Reader
129129
public function __construct($input, $encoding = null)
130130
{
131131
$this->input = (string) $input;
132+
// Remove UTF-8 BOM
133+
if (substr($this->input, 0, 3) === pack('H*', 'EFBBBF')) {
134+
$this->input = substr($this->input, 3);
135+
}
132136
$this->encoding = $encoding ?: $this->defaultEncoding;
133137

134138
$this->position = 0;

tests/Phug/ReaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,4 +874,14 @@ public function testReadmeSecondLexingExample()
874874
'title' => '(title ? title : \'Sorry, no title.\')',
875875
], ], $element);
876876
}
877+
878+
/**
879+
* @covers ::__construct
880+
* @group utf8
881+
*/
882+
public function testUtf8BomRemove()
883+
{
884+
$reader = new Reader(file_get_contents(__DIR__.'/../utf8bom.pug'));
885+
self::assertTrue($reader->peekChar('p'));
886+
}
877887
}

tests/utf8bom.pug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
p "foo"

0 commit comments

Comments
 (0)