Skip to content

Commit 7924c45

Browse files
Merge remote-tracking branch '37570/avoid-xml-exceptions' into comps_78764_2205
2 parents 39f9f9c + 31b66a5 commit 7924c45

File tree

1 file changed

+18
-11
lines changed
  • lib/internal/Magento/Framework/View/Model/Layout

1 file changed

+18
-11
lines changed

lib/internal/Magento/Framework/View/Model/Layout/Merge.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Framework\View\Model\Layout;
77

@@ -564,6 +564,21 @@ protected function _loadXmlString($xmlString)
564564
return simplexml_load_string($xmlString, \Magento\Framework\View\Layout\Element::class);
565565
}
566566

567+
/**
568+
* Return object representation of XML string, or false, if XML was invalid
569+
*
570+
* @param string $xmlString
571+
* @return \SimpleXMLElement|false
572+
*/
573+
protected function _safeLoadXmlString(string $xmlString): \SimpleXMLElement|false
574+
{
575+
return simplexml_load_string(
576+
$xmlString,
577+
\Magento\Framework\View\Layout\Element::class,
578+
LIBXML_NOWARNING | LIBXML_NOERROR
579+
);
580+
}
581+
567582
/**
568583
* Merge layout update by handle
569584
*
@@ -988,15 +1003,7 @@ public function getCacheId()
9881003
private function extractHandlers(): void
9891004
{
9901005
foreach ($this->updates as $update) {
991-
$updateXml = null;
992-
993-
try {
994-
$updateXml = is_string($update) ? $this->_loadXmlString($update) : false;
995-
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
996-
} catch (\Exception $exception) {
997-
// ignore invalid
998-
}
999-
1006+
$updateXml = is_string($update) ? $this->_safeLoadXmlString($update) : false;
10001007
if ($updateXml && strtolower($updateXml->getName()) == 'update' && isset($updateXml['handle'])) {
10011008
$this->addHandle((string)$updateXml['handle']);
10021009
}

0 commit comments

Comments
 (0)