1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-27 03:21:26 +03:00

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.
This commit is contained in:
Kasimier T. Buchcik 2006-04-19 11:20:49 +00:00
parent cdf59aa58f
commit b63d2fab2d
6 changed files with 55 additions and 2 deletions

View File

@ -1,3 +1,10 @@
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()

View File

@ -0,0 +1 @@
./test/schemas/restriction-enum-1_0.xml fails to validate

View File

@ -0,0 +1,2 @@
./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'.

View File

@ -0,0 +1,7 @@
<?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>

View File

@ -0,0 +1,19 @@
<?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>

View File

@ -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));