diff --git a/src/HTML5DOMDocument.php b/src/HTML5DOMDocument.php index 2054b46..cea8993 100644 --- a/src/HTML5DOMDocument.php +++ b/src/HTML5DOMDocument.php @@ -288,10 +288,6 @@ private function addBodyElementIfMissing(): bool */ public function saveHTML(\DOMNode $node = null): string { - if (!$this->loaded) { - return ''; - } - $nodeMode = $node !== null; if ($nodeMode && $node instanceof \DOMDocument) { $nodeMode = false; diff --git a/tests/Test.php b/tests/Test.php index 0108208..43be52a 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -42,7 +42,7 @@ public function testSaveHTML() $dom = new HTML5DOMDocument(); // without loading anything - $this->assertTrue('' === $dom->saveHTML()); + $this->assertTrue('' === $dom->saveHTML()); } /** @@ -1465,4 +1465,15 @@ public function testInternalEntityFromGetters(string $dom, string $expectedFromP static::assertEquals($expectedFromGetter, $node->getTextContent()); } } + + /** + * + */ + public function testSaveHTMLWithoutLoadHTML() + { + $dom = new \IvoPetkov\HTML5DOMDocument(); + $dom->appendChild($dom->createElement('div')); + $dom->querySelector('*')->innerHTML = 'text'; + $this->assertEquals('