Repository navigation
🐛 fix(xsd): reject attributes on simple types - #2138
Conversation
XSD 1.0 §3.3.4 lets a simple-typed element carry no attributes except the four xsi ones, but the simple-type branches never checked attributes; only complex types did. Both simple-type branches now check them: a type= reference and an inline simpleType. Namespace declarations are not attributes in the infoset and stay allowed. The xsi attributes are matched by namespace, so a different prefix bound to the XSI namespace is accepted and an unrelated prefix is not. Fixes tox-dev#2128.
Merging this PR will degrade performance by 24.96%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
XMLSchema.validate()accepted an element with a simple type that carried attributes, and reported the document valid. XML Schema does not allow such an element to have attributes beyond thexsi:ones, so the document was wrong to pass. ✅ After this change the element fails with astructureerror, and the document is reported invalid.Under XML Schema Part 1, section 3.3.4, an element with a simple type may carry no attributes other than
xsi:type,xsi:nil,xsi:schemaLocationandxsi:noNamespaceSchemaLocation. Namespace declarations are not attributes in the infoset, so they stay allowed.The check runs in both simple-type routes: a built-in or named simple type, and an inline
xs:simpleType. Local declarations andref=to a global element reach the same check. Thexsi:attributes are matched by namespace, so another prefix bound to the XSI namespace is accepted.Behavior changes
xsi:attributes now produces onestructureerror for the element.xml:*and attributes in other namespaces, are rejected on simple-typed elements, since the spec names no exception for them.Fixes #2128.