Skip to content

Commit 69a525f

Browse files
authored
Merge pull request #141 from JayBizzle/patch-1
Use `LIBXML_HTML_NODEFDTD` to maintain output consistency
2 parents d95c2f7 + a1fda28 commit 69a525f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Drivers/HtmlDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function serialize($data): string
1919
$domDocument->preserveWhiteSpace = false;
2020
$domDocument->formatOutput = true;
2121

22-
@$domDocument->loadHTML($data); // to ignore HTML5 errors
22+
@$domDocument->loadHTML($data, LIBXML_HTML_NODEFDTD); // to ignore HTML5 errors
2323

2424
$htmlValue = $domDocument->saveHTML();
2525
// Normalize line endings for cross-platform tests.

tests/Unit/Drivers/HtmlDriverTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ public function it_can_serialize_a_html_string_to_pretty_html()
2424

2525
$this->assertEquals($expected, $driver->serialize('<!doctype html><html lang="en"><head></head><body><h1>Hello, world!</h1></body></html>'));
2626
}
27+
28+
/** @test */
29+
public function test_for_issue_140()
30+
{
31+
$driver = new HtmlDriver();
32+
33+
$expected = implode("\n", [
34+
'<!DOCTYPE html>',
35+
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">',
36+
'<head>',
37+
'<!--[if !mso]><!-->',
38+
'<meta http-equiv="X-UA-Compatible" content="IE=edge">',
39+
'<!--<![endif]-->',
40+
'</head>',
41+
'<body><h1>Hello, world!</h1></body>',
42+
'</html>',
43+
'',
44+
]);
45+
46+
$this->assertEquals($expected, $driver->serialize($expected));
47+
}
2748

2849
/** @test */
2950
public function it_can_only_serialize_strings()

0 commit comments

Comments
 (0)