Skip to content

🐛 fix(xsd): validate prefixed attributes - #2330

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

gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/xsd-prefixed-attrs

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

XML Schema validation skipped every attribute whose name carries a prefix, so a namespace-qualified attribute passed whatever the schema said about its namespace or its type (#2291). 🔐 Once this merges, an attribute that an xs:anyAttribute namespace rule forbids is rejected, and a declared prefixed attribute is checked against its declared type.

A prefixed attribute now matches a declaration or a wildcard by the namespace name its prefix binds in scope, the same way an unprefixed attribute already matched by its local name. The validator keeps the namespace lookup on the element that owns the attributes, so the cost sits on attributes that have a prefix. ✨ The trade-off: the xsi:type, xsi:nil, xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes stay unchecked, as XML Schema 1.1 Part 1, section 3.4.4.2 allows, and xmlns declarations are not attributes to check.

Behavior changes

An undeclared xml: attribute, such as xml:lang, is now reported unless a wildcard admits it, as the specification requires. An undeclared prefixed attribute that no wildcard admits is reported the same way an undeclared unprefixed one already was. A prefix with no declaration in scope leaves the whole name as an attribute in no namespace, so it is checked against no-namespace declarations and wildcards and reported when neither admits it.

Fixes #2291

Prefixed attributes were skipped by the XSD attribute check, so declared
prefixed attributes were never validated and xs:anyAttribute namespace and
processContents settings never applied to them.

Match each attribute by namespace name, resolved through the declarations
in scope, against declared attributes and attribute wildcards. xmlns
declarations and the xsi:type, xsi:nil, xsi:schemaLocation and
xsi:noNamespaceSchemaLocation attributes stay unchecked.

Refs tox-dev#2291
@gaborbernat gaborbernat added the bug Something isn't working label Nov 16, 2026
A prefixed attribute whose prefix has no declaration in scope was skipped,
so an invalid attribute passed silently. An HTML-parsed tree keeps such a
name literally, so the whole name is now an attribute in no namespace and
is matched against no-namespace declarations and wildcards like any other
undeclared attribute.
@gaborbernat
gaborbernat merged commit f7e6e4a into tox-dev:main Nov 16, 2026
2 of 45 checks passed
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.

XML Schema validation skips prefixed attributes

1 participant