From 7da3eed51201b4179ad355584eaa131375aab865 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 4 Feb 2022 13:27:13 +0100 Subject: [PATCH] Fix PHP 8.1 tests --- src/Readability.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Readability.php b/src/Readability.php index 3201d98..9d92442 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -264,7 +264,11 @@ class Readability implements LoggerAwareInterface $overlay->appendChild($innerDiv); // without tidy the body can (sometimes) be wiped, so re-create it - if (!(property_exists($this->body, 'childNodes') && null !== $this->body->childNodes)) { + try { + if (!(property_exists($this->body, 'childNodes') && null !== $this->body->childNodes)) { + $this->body = $this->dom->createElement('body'); + } + } catch (\Exception $e) { $this->body = $this->dom->createElement('body'); }