Skip to content

Commit c50b33d

Browse files
committed
Ensure to add the namespace declaration of the QName-value
1 parent 472453a commit c50b33d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/XML/Attribute.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SimpleSAML\XML\Assert\Assert;
99
use SimpleSAML\XML\Constants as C;
1010
use SimpleSAML\XMLSchema\Type\Interface\ValueTypeInterface;
11+
use SimpleSAML\XMLSchema\Type\QNameValue;
1112
use SimpleSAML\XMLSchema\Type\StringValue;
1213

1314
use function array_keys;
@@ -111,6 +112,20 @@ public function toXML(Dom\Element $parent): Dom\Element
111112
strval($this->getAttrValue()),
112113
);
113114

115+
// An xsi:type attribute (but really any attribute) that contains a QNameValue must also have
116+
// a namespace-declaration for the prefix within the scope of the element
117+
$qName = $this->getAttrValue();
118+
if ($qName instanceof QNameValue) {
119+
$qNamePrefix = $qName->getNamespacePrefix();
120+
if ($qNamePrefix !== null && !$parent->lookupPrefix($qNamePrefix->getValue())) {
121+
$parent->setAttributeNS(
122+
C::NS_XMLNS,
123+
'xmlns:' . $qNamePrefix->getValue(),
124+
$qName->getNamespaceURI()->getValue(),
125+
);
126+
}
127+
}
128+
114129
return $parent;
115130
}
116131

0 commit comments

Comments
 (0)