Skip to content

Commit 89715ab

Browse files
authored
Merge pull request #100 from frugan-dev/master
fix!: fix SimpleHtmlDom::__construct(): Argument #1 ($node) must be of type DOMNode, null given
2 parents c04332c + 0d5c9c7 commit 89715ab

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/voku/helper/HtmlMin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,9 +1713,9 @@ private function protectTagHelper(HtmlDomParser $dom, string $selector): HtmlDom
17131713
continue;
17141714
}
17151715

1716-
$this->protectedChildNodes[$this->protected_tags_counter] = $element->parentNode()->innerHtml();
1717-
$parentNode = $element->getNode()->parentNode;
1718-
if ($parentNode !== null) {
1716+
$parentNode = $element->parentNode();
1717+
if ($parentNode->nodeValue !== null) {
1718+
$this->protectedChildNodes[$this->protected_tags_counter] = $parentNode->innerHtml();
17191719
$parentNode->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $this->protected_tags_counter . '"></' . $this->protectedChildNodesHelper . '>';
17201720
}
17211721

tests/HtmlMinTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,4 +1668,23 @@ public function testdoKeepHttpAndHttpsPrefixOnExternalAttributes()
16681668
$htmlMin->doKeepHttpAndHttpsPrefixOnExternalAttributes(false);
16691669
static::assertSame($expected, $htmlMin->minify($html));
16701670
}
1671+
1672+
public function testNullParentNode()
1673+
{
1674+
$html = " <nocompress>foo</nocompress> ";
1675+
$expected = "<nocompress>foo</nocompress>";
1676+
1677+
$htmlMin = new HtmlMin();
1678+
$htmlMin->doOptimizeViaHtmlDomParser(true);
1679+
static::assertSame($expected, $htmlMin->minify($html));
1680+
1681+
// --
1682+
1683+
$html = "<><code>foo</code><>";
1684+
$expected = "<code>foo</code>";
1685+
1686+
$htmlMin = new HtmlMin();
1687+
$htmlMin->doOptimizeViaHtmlDomParser(true);
1688+
static::assertSame($expected, $htmlMin->minify($html));
1689+
}
16711690
}

0 commit comments

Comments
 (0)