Skip to content

Commit aa89b59

Browse files
MatTheCatfabpot
authored andcommitted
[SecurityBundle] Make security schema deterministic
1 parent c840988 commit aa89b59

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

Loader/XmlFileLoader.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,33 @@ private function parseFileToDOM(string $file): \DOMDocument
404404
try {
405405
$dom = XmlUtils::loadFile($file, [$this, 'validateSchema']);
406406
} catch (\InvalidArgumentException $e) {
407-
throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).$e->getMessage(), $e->getCode(), $e);
407+
$invalidSecurityElements = [];
408+
$errors = explode("\n", $e->getMessage());
409+
foreach ($errors as $i => $error) {
410+
if (preg_match("#^\[ERROR 1871] Element '\{http://symfony\.com/schema/dic/security}([^']+)'#", $error, $matches)) {
411+
$invalidSecurityElements[$i] = $matches[1];
412+
}
413+
}
414+
if ($invalidSecurityElements) {
415+
$dom = XmlUtils::loadFile($file);
416+
417+
foreach ($invalidSecurityElements as $errorIndex => $tagName) {
418+
foreach ($dom->getElementsByTagNameNS('http://symfony.com/schema/dic/security', $tagName) as $element) {
419+
if (!$parent = $element->parentNode) {
420+
continue;
421+
}
422+
if ('http://symfony.com/schema/dic/security' !== $parent->namespaceURI) {
423+
continue;
424+
}
425+
if ('provider' === $parent->localName || 'firewall' === $parent->localName) {
426+
unset($errors[$errorIndex]);
427+
}
428+
}
429+
}
430+
}
431+
if ($errors) {
432+
throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).implode("/n", $errors), $e->getCode(), $e);
433+
}
408434
}
409435

410436
$this->validateExtensions($dom, $file);
@@ -777,6 +803,6 @@ private function loadFromExtensions(\DOMDocument $xml)
777803
*/
778804
public static function convertDomElementToArray(\DOMElement $element)
779805
{
780-
return XmlUtils::convertDomElementToArray($element);
806+
return XmlUtils::convertDomElementToArray($element, false);
781807
}
782808
}

0 commit comments

Comments
 (0)