Skip to content

XERCESC-2269: Accept restrictions of a union as substitutable for the union - #67

Open
Rod-O wants to merge 1 commit into
apache:masterfrom
zorba-processor:XERCESC-2269
Open

Rod-O wants to merge 1 commit into
apache:masterfrom
zorba-processor:XERCESC-2269

Conversation

@Rod-O

@Rod-O Rod-O commented Oct 31, 2026

Copy link
Copy Markdown

Fixes XERCESC-2269.

UnionDatatypeValidator::isSubstitutableBy() only compared the candidate
type with the union itself and with its member types. A simple type derived
from the union by restriction, whose base validator is the union, was
therefore not considered validly derived from it, contrary to XML Schema 1.0
"Type Derivation OK (Simple)", clause 2.1. With schema full checking this
rejected valid schemas that restrict a union-typed element to a restriction
of the union ("element 'e' has type that does not derive from type of
corresponding element in the base"); the same check is used for xsi:type
and substitution groups.

The fix walks the candidate's base chain, as
DatatypeValidator::isSubstitutableBy() does, but only while the validator
is a union: restrictions of a union are always unions, and a list whose item
type is the union (whose base validator is also the union) must not match.
The existing toCheck == this test is subsumed by the first iteration.
Member-type handling is unchanged.

Test: new sample test DOMCount4 (CMake and autotools) runs
DOMCount -n -s -f union-restriction.xml on a schema that restricts a
union-typed element to a one-level and a two-level restriction of the union.
It fails on master with the message above and passes with the fix. The full
ctest suite passes (81/81) on Ubuntu 24.04 (GCC 13, ICU transcoder, curl net
accessor). The W3C QT3 schema prod/SchemaImport/unionListDefined.xsd, which
originally exposed the bug, loads with the fix.

Files:

  • src/xercesc/validators/datatype/UnionDatatypeValidator.hpp: the fix.
  • samples/data/union-restriction.xsd, samples/data/union-restriction.xml,
    samples/expected/DOMCount4.log, samples/scripts/DOMCount4,
    samples/CMakeLists.txt, samples/Makefile.am: the regression test.

… union

UnionDatatypeValidator::isSubstitutableBy() only compared the candidate
with the union itself and with its member types. A simple type derived
from the union by restriction (whose base validator is the union) was
therefore not considered validly derived from it, which is wrong per
XML Schema 1.0, Type Derivation OK (Simple), clause 2.1.

With schema full checking this rejected valid schemas in which a complex
type restriction narrows an element of a union type to a restriction of
that union ("element 'e' has type that does not derive from type of
corresponding element in the base"). The same check is used for xsi:type
and substitution groups.

Walk the base chain of the candidate while it is a union (restrictions of
a union are unions; a list whose item type is the union must not match).

Add sample test DOMCount4 with a schema that restricts a union-typed
element to one- and two-level restrictions of the union.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant