Skip to content

🐛 fix(xsd): match wildcards to admitted elements - #2256

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/xsd-wildcard-1786
Nov 16, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/xsd-wildcard-1786

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

The content-model matcher in xsd_match_once skipped every xs:any particle in a choice, and the sequence loop at L628-L631 skipped it in a sequence, so a wildcard consumed no child element whatever its minOccurs, maxOccurs, namespace or processContents said. xsd_collect_attrs did not recognize xs:anyAttribute at 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:any match a child element whose namespace its namespace attribute admits, and an element particle matches only the element of its name. The particle's minOccurs and maxOccurs bound 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_once advances each position past one child that xsd_wild_admits accepts and records the wildcard as that child's claim. The choice and sequence loops hand every particle to xsd_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, and xsd_wild_decl resolves each one against the global element of its name: strict requires that declaration, lax uses it when present, and skip validates 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_attrs now records the first xs:anyAttribute of the type, its base, and its derivations whose namespace constraint admits no namespace. xsd_validate_attrs then accepts an undeclared unprefixed attribute through xsd_validate_wild_attr. That function applies processContents the same way: strict requires a global attribute declaration of the name, lax validates against one when present, and skip validates nothing. A global attribute is in the target namespace, so the lookup happens only when the schema has no target namespace.

Behavior changes

  • A wildcard with minOccurs of 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.
  • An element matched by a strict wildcard with no global element declaration is reported as invalid.
  • lax and skip wildcards validate a matched element only as their processContents directs.
  • An undeclared unprefixed attribute that xs:anyAttribute admits is accepted, and strict reports one that has no global declaration.
  • Prefixed attributes are still not validated, as before. The namespace constraint of xs:anyAttribute therefore applies to unprefixed attributes only.

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
@gaborbernat gaborbernat added the bug Something isn't working label Nov 16, 2026
@gaborbernat
gaborbernat merged commit b6fb646 into tox-dev:main Nov 16, 2026
35 of 45 checks passed
@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 25.07%

1 warning

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

❌ 1 regressed benchmark
✅ 581 untouched benchmarks
⏩ 89 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_mutating_feature[path-xpath-one-cold] 107.2 µs 143 µs -25.07%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing gaborbernat:fix/xsd-wildcard-1786 (d542b43) with main (a3be9b2)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XSD wildcards consume no element during validation

1 participant