Skip to content

Commit

Permalink
Merge pull request #100 from frugan-dev/master
Browse files Browse the repository at this point in the history
fix!: fix SimpleHtmlDom::__construct(): Argument #1 ($node) must be of type DOMNode, null given
  • Loading branch information
voku authored May 25, 2024
2 parents c04332c + 0d5c9c7 commit 89715ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/voku/helper/HtmlMin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1713,9 +1713,9 @@ private function protectTagHelper(HtmlDomParser $dom, string $selector): HtmlDom
continue;
}

$this->protectedChildNodes[$this->protected_tags_counter] = $element->parentNode()->innerHtml();
$parentNode = $element->getNode()->parentNode;
if ($parentNode !== null) {
$parentNode = $element->parentNode();
if ($parentNode->nodeValue !== null) {

Check failure on line 1717 in src/voku/helper/HtmlMin.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Cannot access property $nodeValue on voku\helper\SimpleHtmlDomInterface|null.
$this->protectedChildNodes[$this->protected_tags_counter] = $parentNode->innerHtml();

Check failure on line 1718 in src/voku/helper/HtmlMin.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Cannot call method innerHtml() on voku\helper\SimpleHtmlDomInterface|null.
$parentNode->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $this->protected_tags_counter . '"></' . $this->protectedChildNodesHelper . '>';

Check failure on line 1719 in src/voku/helper/HtmlMin.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Cannot access property $nodeValue on voku\helper\SimpleHtmlDomInterface|null.
}

Expand Down
19 changes: 19 additions & 0 deletions tests/HtmlMinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1668,4 +1668,23 @@ public function testdoKeepHttpAndHttpsPrefixOnExternalAttributes()
$htmlMin->doKeepHttpAndHttpsPrefixOnExternalAttributes(false);
static::assertSame($expected, $htmlMin->minify($html));
}

public function testNullParentNode()
{
$html = " <nocompress>foo</nocompress> ";
$expected = "<nocompress>foo</nocompress>";

$htmlMin = new HtmlMin();
$htmlMin->doOptimizeViaHtmlDomParser(true);
static::assertSame($expected, $htmlMin->minify($html));

// --

$html = "<><code>foo</code><>";
$expected = "<code>foo</code>";

$htmlMin = new HtmlMin();
$htmlMin->doOptimizeViaHtmlDomParser(true);
static::assertSame($expected, $htmlMin->minify($html));
}
}

0 comments on commit 89715ab

Please sign in to comment.