From 415cd6a360f9326fd82480f7a7510e0ee247fbcb Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Thu, 28 Nov 2024 16:30:59 +0000 Subject: [PATCH] Includes: Workaround for PHP 8.3.14 bug Changed DOMText creation to be done via document so its document reference is correct to avoid a bug in PHP 8.3.14. Ref: https://github.com/php/php-src/issues/16967 Fixes #5341 --- app/Entities/Tools/PageIncludeParser.php | 4 ++-- app/Util/HtmlDocument.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Entities/Tools/PageIncludeParser.php b/app/Entities/Tools/PageIncludeParser.php index dad7c29e6..e0b89f158 100644 --- a/app/Entities/Tools/PageIncludeParser.php +++ b/app/Entities/Tools/PageIncludeParser.php @@ -104,10 +104,10 @@ class PageIncludeParser if ($currentOffset < $tagStartOffset) { $previousText = substr($text, $currentOffset, $tagStartOffset - $currentOffset); - $textNode->parentNode->insertBefore(new DOMText($previousText), $textNode); + $textNode->parentNode->insertBefore($this->doc->createTextNode($previousText), $textNode); } - $node = $textNode->parentNode->insertBefore(new DOMText($tagOuterContent), $textNode); + $node = $textNode->parentNode->insertBefore($this->doc->createTextNode($tagOuterContent), $textNode); $includeTags[] = new PageIncludeTag($tagInnerContent, $node); $currentOffset = $tagStartOffset + strlen($tagOuterContent); } diff --git a/app/Util/HtmlDocument.php b/app/Util/HtmlDocument.php index b8c53d439..7517955b9 100644 --- a/app/Util/HtmlDocument.php +++ b/app/Util/HtmlDocument.php @@ -6,6 +6,7 @@ use DOMDocument; use DOMElement; use DOMNode; use DOMNodeList; +use DOMText; use DOMXPath; /** @@ -81,6 +82,14 @@ class HtmlDocument return $element; } + /** + * Create a new text node within this document. + */ + public function createTextNode(string $text): DOMText + { + return $this->document->createTextNode($text); + } + /** * Get an element within the document of the given ID. */