Commit 9b02e295 authored by Kasimier T. Buchcik's avatar Kasimier T. Buchcik
Browse files

Fixed bug #341337, reported by David Grohmann. The code expected a node

* xmlschemas.c: Fixed bug #341337, reported by David Grohmann.
  The code expected a node (xmlNodePtr) on the info for a
  non-existent default attribute, which clearly cannot be
  expected, since the attribute does not exist. I can only
  guess that this sneaked trying to eliminate the query
  for the owner-element, which is unavoidable actually.
  Note that creation of default attributes won't have an
  effect if validating via SAX/XMLReader; i.e., the processor
  won't fire additional start-attribute events (I'm not even
  sure if Libxml2 has such a SAX-event; I think it hands them
  all over in the start-element event).
parent 7c7c0590
Thu May 11 18:03:49 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xmlschemas.c: Fixed bug #341337, reported by David Grohmann.
The code expected a node (xmlNodePtr) on the info for a
non-existent default attribute, which clearly cannot be
expected, since the attribute does not exist. I can only
guess that this sneaked trying to eliminate the query
for the owner-element, which is unavoidable actually.
Note that creation of default attributes won't have an
effect if validating via SAX/XMLReader; i.e., the processor
won't fire additional start-attribute events (I'm not even
sure if Libxml2 has such a SAX-event; I think it hands them
all over in the start-element event).
Tue May 9 21:47:58 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xmlschemas.c: Fixed bug #341150, reported by Michael Romer.
......@@ -11,7 +25,6 @@ Tue May 9 21:47:58 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
result/schemas/subst-group-1_0_1.err: Added regression test
supplied by Michael Romer for bug #341150.
Sat May 6 11:05:24 HKT 2006 William M. Brack <wbrack@mmm.com.hk>
* relaxng.c: Fixed compilation error with patch supplied by
......
......@@ -24826,6 +24826,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
xmlSchemaAttrInfoPtr iattr, tmpiattr;
int i, j, found, nbAttrs, nbUses;
int xpathRes = 0, res, wildIDs = 0, fixed;
xmlNodePtr defAttrOwnerElem = NULL;
/*
* SPEC (cvc-attribute)
......@@ -25067,6 +25068,15 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
if (vctxt->nbAttrInfos == 0)
return (0);
/*
* Get the owner element; needed for creation of default attributes.
* This fixes bug #341337, reported by David Grohmann.
*/
if (vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) {
xmlSchemaNodeInfoPtr ielem = vctxt->elemInfos[vctxt->depth];
if (ielem && ielem->node && ielem->node->doc)
defAttrOwnerElem = ielem->node;
}
/*
* Validate values, create default attributes, evaluate IDCs.
*/
......@@ -25108,8 +25118,10 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
if (iattr->state == XML_SCHEMAS_ATTR_DEFAULT) {
/*
* Default/fixed attributes.
* We need the value only if we need to resolve IDCs or
* will create default attributes.
*/
if (xpathRes) {
if ((xpathRes) || (defAttrOwnerElem)) {
if (iattr->use->defValue != NULL) {
iattr->value = (xmlChar *) iattr->use->defValue;
iattr->val = iattr->use->defVal;
......@@ -25139,8 +25151,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
* VAL TODO: Should we use the *normalized* value? This currently
* uses the *initial* value.
*/
if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) &&
(iattr->node != NULL) && (iattr->node->doc != NULL)) {
if (defAttrOwnerElem) {
xmlChar *normValue;
const xmlChar *value;
......@@ -25154,7 +25166,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
value = BAD_CAST normValue;
if (iattr->nsName == NULL) {
if (xmlNewProp(iattr->node->parent,
if (xmlNewProp(defAttrOwnerElem,
iattr->localName, value) == NULL) {
VERROR_INT("xmlSchemaVAttributesComplex",
"callling xmlNewProp()");
......@@ -25165,8 +25177,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
} else {
xmlNsPtr ns;
ns = xmlSearchNsByHref(iattr->node->doc,
iattr->node->parent, iattr->nsName);
ns = xmlSearchNsByHref(defAttrOwnerElem->doc,
defAttrOwnerElem, iattr->nsName);
if (ns == NULL) {
xmlChar prefix[12];
int counter = 0;
......@@ -25177,8 +25189,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
*/
do {
snprintf((char *) prefix, 12, "p%d", counter++);
ns = xmlSearchNs(iattr->node->doc,
iattr->node->parent, BAD_CAST prefix);
ns = xmlSearchNs(defAttrOwnerElem->doc,
defAttrOwnerElem, BAD_CAST prefix);
if (counter > 1000) {
VERROR_INT(
"xmlSchemaVAttributesComplex",
......@@ -25198,8 +25210,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
* If we have QNames: do we need to ensure there's a
* prefix defined for the QName?
*/
xmlNewNsProp(iattr->node->parent, ns,
iattr->localName, value);
xmlNewNsProp(defAttrOwnerElem, ns, iattr->localName, value);
}
if (normValue != NULL)
xmlFree(normValue);
......
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