Skip to content

Commit 3cc4dd9

Browse files
committed
Reduce duplicate namespaces
1 parent 44d4187 commit 3cc4dd9

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/XML/CanonicalizableElementTrait.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use DOMElement;
88
use SimpleSAML\XMLSecurity\Constants as C;
99
use SimpleSAML\XMLSecurity\Exception\CanonicalizationFailedException;
10+
use SimpleSAML\XMLSecurity\Exception\ReferenceValidationFailedException;
11+
use SimpleSAML\XMLSecurity\Utils\XPath;
1012
use SimpleSAML\XMLSecurity\XML\ds\Transforms;
1113
use SimpleSAML\XPath\Constants as XPATH_C;
1214

@@ -140,15 +142,22 @@ public function processTransforms(
140142
$arXPath = [];
141143
$xpathValue = $xpath->getContent()->getValue();
142144
$arXPath['query'] = '(.//. | .//@* | .//namespace::*)[' . $xpathValue . ']';
143-
144-
// $arXpath['namespaces'] = $xpath->getNamespaces();
145-
// TODO: review if $nsnode->localName is equivalent to the keys in getNamespaces()
146-
// $nslist = $xp->query('./namespace::*', $node);
147-
// foreach ($nslist as $nsnode) {
148-
// if ($nsnode->localName != "xml") {
149-
// $arXPath['namespaces'][$nsnode->localName] = $nsnode->nodeValue;
150-
// }
151-
// }
145+
$arXpath['namespaces'] = $xpath->getNamespaces();
146+
147+
$xpCache = XPath::getXPath($data);
148+
$nslist = $xpCache->query('./namespace::*', $xpath->toXML());
149+
Assert::lessThanEq(
150+
$nslist->count(),
151+
C::MAX_XPATH_NAMESPACES,
152+
ReferenceValidationFailedException::class,
153+
'Too many namespaces.',
154+
);
155+
156+
foreach ($nslist as $nsnode) {
157+
if ($nsnode->localName != "xml") {
158+
$arXPath['namespaces'][$nsnode->localName] = $nsnode->nodeValue;
159+
}
160+
}
152161
}
153162
break;
154163
}

0 commit comments

Comments
 (0)