diff --git a/docs/changes/1.x/1.5.0.md b/docs/changes/1.x/1.5.0.md index b96865bada..7a03cc3dc8 100644 --- a/docs/changes/1.x/1.5.0.md +++ b/docs/changes/1.x/1.5.0.md @@ -7,6 +7,7 @@ ### Bug fixes - Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776) +- Prevent `htmlspecialchars()` deprecation warnings by defaulting `null` values to empty strings in `AbstractPart` by [@dafydd-rhys](https://github.com/dafydd-rhys) fixing [#2829](https://github.com/PHPOffice/PHPWord/issues/2829) in [#2828](https://github.com/PHPOffice/PHPWord/pull/2828) ### Miscellaneous diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 9d49573d69..c9c6385e39 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -302,7 +302,7 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par $nodes = $xmlReader->getElements('w:r|w:hyperlink', $domNode); $hasRubyElement = $xmlReader->elementExists('w:r/w:ruby', $domNode); if ($nodes->length === 1 && !$hasRubyElement) { - $textContent = htmlspecialchars($xmlReader->getValue('w:t', $nodes->item(0)), ENT_QUOTES, 'UTF-8'); + $textContent = htmlspecialchars($xmlReader->getValue('w:t', $nodes->item(0)) ?? '', ENT_QUOTES, 'UTF-8'); } else { $textContent = new TextRun($paragraphStyle); foreach ($nodes as $node) { @@ -559,14 +559,14 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract if ($fallbackElements->length) { $fallback = $fallbackElements->item(0); // TextRun - $textContent = htmlspecialchars($fallback->nodeValue, ENT_QUOTES, 'UTF-8'); + $textContent = htmlspecialchars($fallback->nodeValue ?? '', ENT_QUOTES, 'UTF-8'); $parent->addText($textContent, $fontStyle, $paragraphStyle); } } } elseif ($node->nodeName == 'w:t' || $node->nodeName == 'w:delText') { // TextRun - $textContent = htmlspecialchars($xmlReader->getValue('.', $node), ENT_QUOTES, 'UTF-8'); + $textContent = htmlspecialchars($xmlReader->getValue('.', $node) ?? '', ENT_QUOTES, 'UTF-8'); if ($runParent->nodeName == 'w:hyperlink') { $rId = $xmlReader->getAttribute('r:id', $runParent);