File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -1477,14 +1477,23 @@ private function isPhrasingContent($node): bool
14771477 );
14781478 }
14791479
1480+ /**
1481+ * Checks if `$node` has only whitespace and a single element with `$tag` for the tag name.
1482+ * Returns false if `$node` contains non-empty text nodes
1483+ * or if it contains no element with given tag or more than 1 element.
1484+ */
14801485 private function hasSingleTagInsideElement (\DOMElement $ node , string $ tag ): bool
14811486 {
1482- if (1 !== $ node ->childNodes ->length || $ node ->childNodes ->item (0 )->nodeName !== $ tag ) {
1487+ $ childNodes = iterator_to_array ($ node ->childNodes );
1488+ $ children = array_filter ($ childNodes , fn ($ childNode ) => $ childNode instanceof \DOMElement);
1489+
1490+ // There should be exactly 1 element child with given tag
1491+ if (1 !== \count ($ children ) || $ children [0 ]->nodeName !== $ tag ) {
14831492 return false ;
14841493 }
14851494
14861495 $ a = array_filter (
1487- iterator_to_array ( $ node -> childNodes ) ,
1496+ $ childNodes ,
14881497 fn ($ childNode ) => $ childNode instanceof \DOMText && preg_match ($ this ->regexps ['hasContent ' ], $ this ->getInnerText ($ childNode ))
14891498 );
14901499
You can’t perform that action at this time.
0 commit comments