diff options
author | Matt Butcher <[email protected]> | 2014-09-30 20:20:54 -0600 |
---|---|---|
committer | Matt Butcher <[email protected]> | 2014-09-30 20:20:54 -0600 |
commit | f50e87904ed0857ea2dead2ae4facf7d95c743fd (patch) | |
tree | 462e82f24b7891aff0f24eba0aa7d3bb95f6877f | |
parent | 496b8033abfb9d6de6005b3f6226e1f046899395 (diff) | |
parent | 75fe1de1a15c5f83da53059efaef7c67902c9043 (diff) |
Merge pull request #61 from goetas/issue_50
Handling empty documents
-rw-r--r-- | src/HTML5/Serializer/OutputRules.php | 6 | ||||
-rw-r--r-- | test/HTML5/Serializer/OutputRulesTest.php | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php index 7ea7c6a..c009698 100644 --- a/src/HTML5/Serializer/OutputRules.php +++ b/src/HTML5/Serializer/OutputRules.php @@ -115,8 +115,10 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface public function document($dom) { $this->doctype(); - $this->traverser->node($dom->documentElement); - $this->nl(); + if ($dom->documentElement) { + $this->traverser->node($dom->documentElement); + $this->nl(); + } } protected function doctype() diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php index e89d723..aa2e0c5 100644 --- a/test/HTML5/Serializer/OutputRulesTest.php +++ b/test/HTML5/Serializer/OutputRulesTest.php @@ -76,6 +76,19 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEquals($expected, stream_get_contents($stream, - 1, 0)); } + public function testEmptyDocument() + { + $dom = $this->html5->loadHTML(''); + + $stream = fopen('php://temp', 'w'); + $r = new OutputRules($stream, $this->html5->getOptions()); + $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); + + $r->document($dom); + $expected = '<!DOCTYPE html>' . PHP_EOL; + $this->assertEquals($expected, stream_get_contents($stream, - 1, 0)); + } + public function testDoctype() { $dom = $this->html5->loadHTML('<!doctype html><html lang="en"><body>foo</body></html>'); |