Skip to content

Commit e9218c3

Browse files
committed
Fix: prevent null being passed to htmlspecialchars() in AbstractPart.php
1 parent 0ab0b49 commit e9218c3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par
302302
$nodes = $xmlReader->getElements('w:r|w:hyperlink', $domNode);
303303
$hasRubyElement = $xmlReader->elementExists('w:r/w:ruby', $domNode);
304304
if ($nodes->length === 1 && !$hasRubyElement) {
305-
$textContent = htmlspecialchars($xmlReader->getValue('w:t', $nodes->item(0)), ENT_QUOTES, 'UTF-8');
305+
$textContent = htmlspecialchars($xmlReader->getValue('w:t', $nodes->item(0)) ?? '', ENT_QUOTES, 'UTF-8');
306306
} else {
307307
$textContent = new TextRun($paragraphStyle);
308308
foreach ($nodes as $node) {
@@ -559,14 +559,14 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract
559559
if ($fallbackElements->length) {
560560
$fallback = $fallbackElements->item(0);
561561
// TextRun
562-
$textContent = htmlspecialchars($fallback->nodeValue, ENT_QUOTES, 'UTF-8');
562+
$textContent = htmlspecialchars($fallback->nodeValue ?? '', ENT_QUOTES, 'UTF-8');
563563

564564
$parent->addText($textContent, $fontStyle, $paragraphStyle);
565565
}
566566
}
567567
} elseif ($node->nodeName == 'w:t' || $node->nodeName == 'w:delText') {
568568
// TextRun
569-
$textContent = htmlspecialchars($xmlReader->getValue('.', $node), ENT_QUOTES, 'UTF-8');
569+
$textContent = htmlspecialchars($xmlReader->getValue('.', $node) ?? '', ENT_QUOTES, 'UTF-8');
570570

571571
if ($runParent->nodeName == 'w:hyperlink') {
572572
$rId = $xmlReader->getAttribute('r:id', $runParent);

0 commit comments

Comments
 (0)