Commit b63d2fab authored by Kasimier T. Buchcik's avatar Kasimier T. Buchcik

Fixed incorrect validation of restricted enumerations. Added related

* xmlschemas.c test/schemas/restriction-enum-1*
  result/schemas/restriction-enum-1*: Fixed incorrect
  validation of restricted enumerations. Added related
  regression tests.
parent cdf59aa5
Wed Apr 19 13:16:23 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xmlschemas.c test/schemas/restriction-enum-1*
result/schemas/restriction-enum-1*: Fixed incorrect
validation of restricted enumerations. Added related
regression tests.
Thu Apr 13 09:47:25 CEST 2006 Daniel Veillard <daniel@veillard.com>
* xmlschemas.c: fixing a deallocation problem in xmlSchemaAddSchemaDoc()
......
./test/schemas/restriction-enum-1_0.xml fails to validate
./test/schemas/restriction-enum-1_0.xml:7: element foo: Schemas validity error : Element 'foo': [facet 'enumeration'] The value 'c' is not an element of the set {'a', 'b', 'd'}.
./test/schemas/restriction-enum-1_0.xml:7: element foo: Schemas validity error : Element 'foo': 'c' is not a valid value of the atomic type 'barType'.
<?xml version="1.0"?>
<!-- This instance should raise an error, since in
"restriction-enum-1_1.xsd", the restricting enumeration
rules out the value "c" (which is allowed in the restricted
type).
-->
<foo>c</foo>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="fooType">
<xs:restriction base="xs:string">
<xs:enumeration value="a"/>
<xs:enumeration value="b"/>
<xs:enumeration value="c"/>
<xs:enumeration value="d"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="barType">
<xs:restriction base="fooType">
<xs:enumeration value="a"/>
<xs:enumeration value="b"/>
<xs:enumeration value="d"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="foo" type="barType" />
</xs:schema>
......@@ -578,7 +578,7 @@ struct _xmlSchemaConstructionCtxt {
struct _xmlSchemaParserCtxt {
int type;
void *errCtxt; /* user specific error context */
void *errCtxt; /* user specific error context */
xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
int err;
......@@ -1774,7 +1774,7 @@ xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
xmlSchemaFacetPtr facet;
xmlSchemaWhitespaceValueType ws;
xmlChar *value = NULL;
int res;
int res, found = 0;
if (*buf != NULL)
xmlFree(*buf);
......@@ -1788,6 +1788,7 @@ xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
for (facet = type->facets; facet != NULL; facet = facet->next) {
if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
continue;
found = 1;
res = xmlSchemaGetCanonValueWhtspExt(facet->val,
ws, &value);
if (res == -1) {
......@@ -1810,6 +1811,14 @@ xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
value = NULL;
}
}
/*
* The enumeration facet of a type restricts the enumeration
* facet of the ancestor type; i.e., such restricted enumerations
* do not belong to the set of the given type. Thus we break
* on the first found enumeration.
*/
if (found)
break;
type = type->baseType;
} while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));
......@@ -23912,6 +23921,14 @@ pattern_and_enum:
}
if (ret != 0)
break;
/*
* Break on the first set of enumerations. Any additional
* enumerations which might be existent on the ancestors
* of the current type are restricted by this set; thus
* *must* *not* be taken into account.
*/
if (found)
break;
tmpType = tmpType->baseType;
} while ((tmpType != NULL) &&
(tmpType->type != XML_SCHEMA_TYPE_BASIC));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment