Skip to content

Commit ad8802c

Browse files
authored
Merge pull request #168 from idimopoulos/html5_encoding
Set default encoding in the DOMDocument object
2 parents c24cd7e + 5f71e6c commit ad8802c

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/HTML5/Parser/DOMTreeBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public function __construct($isFragment = false, array $options = array())
176176
$dt = $impl->createDocumentType('html');
177177
// $this->doc = \DOMImplementation::createDocument(NULL, 'html', $dt);
178178
$this->doc = $impl->createDocument(null, null, $dt);
179+
$this->doc->encoding = !empty($options['encoding']) ? $options['encoding'] : 'UTF-8';
179180
}
180181

181182
$this->errors = array();

test/HTML5/Parser/DOMTreeBuilderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function testDocument()
5252
$html = '<!DOCTYPE html><html></html>';
5353
$doc = $this->parse($html);
5454

55+
$this->assertEquals('UTF-8', $doc->encoding);
5556
$this->assertInstanceOf('\DOMDocument', $doc);
5657
$this->assertEquals('html', $doc->documentElement->tagName);
5758
$this->assertEquals('http://www.w3.org/1999/xhtml', $doc->documentElement->namespaceURI);

0 commit comments

Comments
 (0)