Skip to content

Commit

Permalink
[BUGFIX] Skip any style elements with null value, but still remove them
Browse files Browse the repository at this point in the history
Psalm indicates that `DOMNode::nodeValue` could be `null`,
perhaps for entirely empty `<style>` elements.

If such are encountered during pre-processing, still remove them from the DOM,
but don't append their contents to the CSS to be inlined with extra line-breaks.
  • Loading branch information
JakeQZ committed Sep 10, 2023
1 parent dd94c6f commit e44ab87
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 0 additions & 3 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
}
)]]></code>
</InvalidArgument>
<PossiblyNullOperand>
<code><![CDATA[$styleNode->nodeValue]]></code>
</PossiblyNullOperand>
</file>
<file src="tests/Support/Constraint/CssConstraint.php">
<DirectConstructorCall>
Expand Down
4 changes: 3 additions & 1 deletion src/CssInliner.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ private function getCssFromAllStyleNodes(): string

$css = '';
foreach ($styleNodes as $styleNode) {
$css .= "\n\n" . $styleNode->nodeValue;
if ($styleNode->nodeValue !== null) {
$css .= "\n\n" . $styleNode->nodeValue;
}
$parentNode = $styleNode->parentNode;
if ($parentNode instanceof \DOMNode) {
$parentNode->removeChild($styleNode);
Expand Down

0 comments on commit e44ab87

Please sign in to comment.