From 79adb60cf571ffa7ee33aff9320cb33ae5ed2e9a Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 7 Mar 2024 23:09:25 +0100 Subject: [PATCH] Qual: Add instanceof tests to help static typing analysis (#28696) # Qual: Add instanceof tests to help static typing analysis Added instanceof tests to help identify that properties exist. --- htdocs/core/lib/functions.lib.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5c57d266301..f13707b4a36 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7630,9 +7630,14 @@ function dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes $dom = new DOMDocument(null, 'UTF-8'); $dom->loadHTML($stringtoclean, LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOXMLDECL); - if (is_object($dom)) { + if ($dom instanceof DOMDocument) { for ($els = $dom->getElementsByTagname('*'), $i = $els->length - 1; $i >= 0; $i--) { - for ($attrs = $els->item($i)->attributes, $ii = $attrs->length - 1; $ii >= 0; $ii--) { + $el = $els->item($i); + if (!$el instanceof DOMElement) { + continue; + } + $attrs = $el->attributes; + for ($ii = $attrs->length - 1; $ii >= 0; $ii--) { //var_dump($attrs->item($ii)); if (!empty($attrs->item($ii)->name)) { if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {