Skip to content

Commit 3ac405a

Browse files
committed
ACP2E-3326: catch and treat exception on certain versions of php / OS combinations.
1 parent 23ef146 commit 3ac405a

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

app/code/Magento/PageBuilder/Model/Stage/HtmlFilter.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,43 @@ public function filterHtml(string $content): string
7878
);
7979
foreach ($htmlContentTypes as $htmlContentType) {
8080
/* @var \DOMElement $htmlContentType */
81-
$innerHTML = '';
82-
$children = $htmlContentType->childNodes;
83-
foreach ($children as $child) {
84-
$innerHTML .= $child->ownerDocument->saveXML($child);
85-
}
8681
$htmlContentType->setAttribute(
8782
"class",
8883
$htmlContentType->getAttribute("class") . " placeholder-html-code"
8984
);
85+
86+
$innerHTML = $this->getChildrenInnerHtml($htmlContentType);
87+
9088
$htmlContentType->nodeValue = htmlentities($innerHTML);
9189
}
9290
return substr(trim($dom->saveHTML()), 5, -6);
9391
}
92+
93+
/**
94+
* Get inner HTML of element's children
95+
*
96+
* @param \DOMElement $element
97+
* @return string
98+
*/
99+
private function getChildrenInnerHtml(\DOMElement $element): string
100+
{
101+
$innerHTML = '';
102+
$childrenIterator = $element->childNodes->getIterator();
103+
while ($childrenIterator->valid()) {
104+
$child = $childrenIterator->current();
105+
try {
106+
$ownerDocument = $child->ownerDocument;
107+
} catch (\Error $error) {
108+
$ownerDocument = null;
109+
$this->loggerInterface->critical($error->getMessage());
110+
}
111+
if ($ownerDocument === null) {
112+
$childrenIterator->next();
113+
continue;
114+
}
115+
$innerHTML .= $ownerDocument->saveXML($child);
116+
$childrenIterator->next();
117+
}
118+
return $innerHTML;
119+
}
94120
}

0 commit comments

Comments
 (0)