Skip to content

Commit

Permalink
[SecurityBundle] Make security schema deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
MatTheCat authored and fabpot committed Aug 19, 2024
1 parent c840988 commit aa89b59
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,33 @@ private function parseFileToDOM(string $file): \DOMDocument
try {
$dom = XmlUtils::loadFile($file, [$this, 'validateSchema']);
} catch (\InvalidArgumentException $e) {
throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).$e->getMessage(), $e->getCode(), $e);
$invalidSecurityElements = [];
$errors = explode("\n", $e->getMessage());
foreach ($errors as $i => $error) {
if (preg_match("#^\[ERROR 1871] Element '\{http://symfony\.com/schema/dic/security}([^']+)'#", $error, $matches)) {
$invalidSecurityElements[$i] = $matches[1];
}
}
if ($invalidSecurityElements) {
$dom = XmlUtils::loadFile($file);

foreach ($invalidSecurityElements as $errorIndex => $tagName) {
foreach ($dom->getElementsByTagNameNS('http://symfony.com/schema/dic/security', $tagName) as $element) {
if (!$parent = $element->parentNode) {
continue;
}
if ('http://symfony.com/schema/dic/security' !== $parent->namespaceURI) {
continue;
}
if ('provider' === $parent->localName || 'firewall' === $parent->localName) {
unset($errors[$errorIndex]);
}
}
}
}
if ($errors) {
throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).implode("/n", $errors), $e->getCode(), $e);
}
}

$this->validateExtensions($dom, $file);
Expand Down Expand Up @@ -777,6 +803,6 @@ private function loadFromExtensions(\DOMDocument $xml)
*/
public static function convertDomElementToArray(\DOMElement $element)
{
return XmlUtils::convertDomElementToArray($element);
return XmlUtils::convertDomElementToArray($element, false);
}
}

0 comments on commit aa89b59

Please sign in to comment.