Rodolfo Ochoa created XERCESC-2269:
--------------------------------------

             Summary: Schema full checking rejects restriction of a union-typed 
element to a restriction of that union ("does not derive from type of 
corresponding element in the base")
                 Key: XERCESC-2269
                 URL: https://issues.apache.org/jira/browse/XERCESC-2269
             Project: Xerces-C++
          Issue Type: Bug
          Components: Validating Parser (XML Schema)
    Affects Versions: 3.3.0
            Reporter: Rodolfo Ochoa


With schema full checking enabled ({{-f}} in the samples, 
{{XMLUni::fgXercesSchemaFullChecking}}), Xerces-C rejects a valid XML Schema 
1.0 document in which a complex type derived by restriction narrows an element 
declared with a union simple type to a simple type that is itself a restriction 
of that union:

{noformat}
Message: element 'e' has type that does not derive from type of corresponding 
element in the base
{noformat}

The schema is valid per XML Schema 1.0 Part 1, 3.14.6 "Type Derivation OK 
(Simple)", clause 2.1 (the derived type's base type definition is the union), 
which is what Particle Valid (Restriction) / NameAndTypeOK clause 7 requires. 
The W3C XQuery/XPath test suite (QT3, 
{{prod/SchemaImport/unionListDefined.xsd}}) uses this pattern; XQuery 
processors built on Xerces-C (e.g. Zorba) fail 161 QT3 test-cases because of it.

Cause: {{UnionDatatypeValidator::isSubstitutableBy(toCheck)}} 
({{src/xercesc/validators/datatype/UnionDatatypeValidator.hpp}}) returns true 
only if {{toCheck == this}} or {{toCheck}} is substitutable for one of the 
member types. A restriction of a union is a {{UnionDatatypeValidator}} whose 
base validator is the union, and its member types are the union's member types, 
so neither test matches: unlike {{DatatypeValidator::isSubstitutableBy}}, the 
union override never walks {{toCheck}}'s base chain. The same function is used 
for {{xsi:type}} and substitution-group checks, so those paths are affected too.

*Minimal reproduction* ({{union-restriction.xsd}}):

{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
  <xs:simpleType name="approximateDate">
    <xs:union memberTypes="xs:date xs:dateTime xs:gYear xs:gYearMonth"/>
  </xs:simpleType>
  <xs:simpleType name="restrictedUnion">
    <xs:restriction base="approximateDate">
      <xs:pattern value="20.*"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="approximateDateType">
    <xs:sequence>
      <xs:element name="e" type="approximateDate"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="restrictedDateType">
    <xs:complexContent>
      <xs:restriction base="approximateDateType">
        <xs:sequence>
          <xs:element name="e" type="restrictedUnion"/>
        </xs:sequence>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
  <xs:element name="restricted" type="restrictedDateType"/>
</xs:schema>
{code}

Instance ({{union-restriction.xml}}):

{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<restricted xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
            xsi:noNamespaceSchemaLocation="union-restriction.xsd">
  <e>2024-02-29</e>
</restricted>
{code}

Steps:

{noformat}
$ DOMCount -n -s -f union-restriction.xml

Error at file .../union-restriction.xsd, line <L>, char <C>   (the restricting 
complexType)
  Message: element 'e' has type that does not derive from type of corresponding 
element in the base
{noformat}

Expected: {{union-restriction.xml: N ms (2 elems).}} Without {{-f}} the 
document parses, since the check is part of schema full checking.

A fix with a regression test is ready (PR to follow).




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to