Repository navigation
🐛 fix(xsd): match wildcards to admitted elements - #2256
Conversation
An xs:any particle was skipped by the content-model matcher, so it consumed no child element, and xs:anyAttribute was not recognized at all. A required wildcard therefore accepted a document with no element in its place and rejected a document whose wildcard element was valid. The wildcard now consumes one child per occurrence within minOccurs and maxOccurs when its namespace constraint admits the child. An unprefixed attribute that xs:anyAttribute admits is accepted, and its processContents decides whether a global declaration validates it. Children a wildcard claims take the declaration their processContents selects: strict requires a global element declaration, lax validates against one when present, and skip validates nothing. Fixes tox-dev#2252
Merging this PR will degrade performance by 25.07%1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
The content-model matcher in
xsd_match_onceskipped everyxs:anyparticle in a choice, and the sequence loop at L628-L631 skipped it in a sequence, so a wildcard consumed no child element whatever itsminOccurs,maxOccurs,namespaceorprocessContentssaid.xsd_collect_attrsdid not recognizexs:anyAttributeat all. A schema that requires a wildcard therefore rejected documents that supplied the element the wildcard admits, and accepted documents that did not supply it. After this change the wildcards follow XML Schema 1.0 Structures, and this PR fixes #2252.The matcher stepped over wildcard particles
XML Schema 1.0 Structures, the wildcard sections of XML Schema 1.0 Structures, makes an
xs:anymatch a child element whose namespace itsnamespaceattribute admits, and an element particle matches only the element of its name. The particle'sminOccursandmaxOccursbound how many children it matches. The old matcher gave every wildcard the empty match, so the particle's occurrence bounds never applied and no child was consumed.The wildcard is now a particle like the others.
xsd_match_onceadvances each position past one child thatxsd_wild_admitsaccepts and records the wildcard as that child's claim. The choice and sequence loops hand every particle toxsd_match_occurs, which applies the occurrence bounds to wildcards as it does to element particles.A child claimed by a wildcard took no declaration
Child declarations were looked up only by the names of the element particles in the content model, so a child that only a wildcard matched was never validated. The processContents of the claiming wildcard now decides it. The claims are stored per child in
xsd_wild_claims, andxsd_wild_declresolves each one against the global element of its name:strictrequires that declaration,laxuses it when present, andskipvalidates nothing. A claim is recorded only where the matcher consumed the child, so an element particle of the same name still decides its own child.A child is claimed by the wildcard that consumed it. Two wildcards that admit the same child in one model are told apart by position in the match, not by the first one in document order.
xs:anyAttribute was not recognized
xsd_collect_attrsnow records the firstxs:anyAttributeof the type, its base, and its derivations whose namespace constraint admits no namespace.xsd_validate_attrsthen accepts an undeclared unprefixed attribute throughxsd_validate_wild_attr. That function applies processContents the same way:strictrequires a global attribute declaration of the name,laxvalidates against one when present, andskipvalidates nothing. A global attribute is in the target namespace, so the lookup happens only when the schema has no target namespace.Behavior changes
minOccursof at least 1 in a sequence or a choice now needs a matching child element. Documents that relied on the wildcard matching nothing are now invalid.strictwildcard with no global element declaration is reported as invalid.laxandskipwildcards validate a matched element only as their processContents directs.xs:anyAttributeadmits is accepted, andstrictreports one that has no global declaration.namespaceconstraint ofxs:anyAttributetherefore applies to unprefixed attributes only.