Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/1.x/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
$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) {
Expand Down Expand Up @@ -369,7 +369,7 @@
}
$formField->setEntries($listEntries);
if (null !== $formField->getValue()) {
$formField->setText($listEntries[$formField->getValue()]);

Check failure on line 372 in src/PhpWord/Reader/Word2007/AbstractPart.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.0)

Offset bool|int|string might not exist on list<string|null>.

Check failure on line 372 in src/PhpWord/Reader/Word2007/AbstractPart.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Offset bool|int|string might not exist on list<string|null>.

Check failure on line 372 in src/PhpWord/Reader/Word2007/AbstractPart.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.4)

Offset bool|int|string might not exist on list<string|null>.

Check failure on line 372 in src/PhpWord/Reader/Word2007/AbstractPart.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.4)

Offset bool|int|string might not exist on list<string|null>.

Check failure on line 372 in src/PhpWord/Reader/Word2007/AbstractPart.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Offset bool|int|string might not exist on list<string|null>.

Check failure on line 372 in src/PhpWord/Reader/Word2007/AbstractPart.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Offset bool|int|string might not exist on list<string|null>.
}

break;
Expand Down Expand Up @@ -559,14 +559,14 @@
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);
Expand Down
Loading