mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
more validation test fixups added duration info for the tests Daniel
* SAX.c parser.c valid.c: more validation test fixups * check-xml-test-suite.py: added duration info for the tests Daniel
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
Tue Feb 19 14:44:53 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* SAX.c parser.c valid.c: more validation test fixups
|
||||||
|
* check-xml-test-suite.py: added duration info for the tests
|
||||||
|
|
||||||
Mon Feb 18 23:25:08 CET 2002 Daniel Veillard <daniel@veillard.com>
|
Mon Feb 18 23:25:08 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* parser.c valid.c: a couple of errors were reported but not
|
* parser.c valid.c: a couple of errors were reported but not
|
||||||
|
192
SAX.c
192
SAX.c
@ -979,6 +979,127 @@ attribute(void *ctx, const xmlChar *fullname, const xmlChar *value)
|
|||||||
xmlFree(ns);
|
xmlFree(ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* xmlCheckDefaultedAttributes:
|
||||||
|
*
|
||||||
|
* Check defaulted attributes from the DTD
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
xmlCheckDefaultedAttributesFromDtd(xmlParserCtxtPtr ctxt,
|
||||||
|
xmlDtdPtr dtd, const xmlChar *name,
|
||||||
|
const xmlChar *prefix, const xmlChar **atts) {
|
||||||
|
xmlElementPtr elemDecl;
|
||||||
|
const xmlChar *att;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ((dtd == NULL) || (name == NULL))
|
||||||
|
return;
|
||||||
|
elemDecl = xmlGetDtdQElementDesc(dtd, name, prefix);
|
||||||
|
if (elemDecl != NULL) {
|
||||||
|
xmlAttributePtr attr = elemDecl->attributes;
|
||||||
|
/*
|
||||||
|
* Check against defaulted attributes from the external subset
|
||||||
|
* if the document is stamped as standalone
|
||||||
|
*/
|
||||||
|
if ((ctxt->myDoc->standalone == 1) &&
|
||||||
|
(ctxt->myDoc->extSubset != NULL) &&
|
||||||
|
(ctxt->validate)) {
|
||||||
|
while (attr != NULL) {
|
||||||
|
if ((attr->defaultValue != NULL) &&
|
||||||
|
(xmlGetDtdQAttrDesc(ctxt->myDoc->extSubset,
|
||||||
|
attr->elem, attr->name,
|
||||||
|
attr->prefix) == attr)) {
|
||||||
|
xmlChar *fulln;
|
||||||
|
|
||||||
|
if (attr->prefix != NULL) {
|
||||||
|
fulln = xmlStrdup(attr->prefix);
|
||||||
|
fulln = xmlStrcat(fulln, BAD_CAST ":");
|
||||||
|
fulln = xmlStrcat(fulln, attr->name);
|
||||||
|
} else {
|
||||||
|
fulln = xmlStrdup(attr->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check that the attribute is not declared in the
|
||||||
|
* serialization
|
||||||
|
*/
|
||||||
|
att = NULL;
|
||||||
|
if (atts != NULL) {
|
||||||
|
i = 0;
|
||||||
|
att = atts[i];
|
||||||
|
while (att != NULL) {
|
||||||
|
if (xmlStrEqual(att, fulln))
|
||||||
|
break;
|
||||||
|
i += 2;
|
||||||
|
att = atts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (att == NULL) {
|
||||||
|
if (ctxt->vctxt.error != NULL)
|
||||||
|
ctxt->vctxt.error(ctxt->vctxt.userData,
|
||||||
|
"standalone: attribute %s on %s defaulted from external subset\n",
|
||||||
|
fulln, attr->elem);
|
||||||
|
/* Waiting on the XML Core WG decision on this
|
||||||
|
ctxt->valid = 0;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attr = attr->nexth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Actually insert defaulted values when needed
|
||||||
|
*/
|
||||||
|
attr = elemDecl->attributes;
|
||||||
|
while (attr != NULL) {
|
||||||
|
if (attr->defaultValue != NULL) {
|
||||||
|
/*
|
||||||
|
* the element should be instantiated in the tree if:
|
||||||
|
* - this is a namespace prefix
|
||||||
|
* - the user required for completion in the tree
|
||||||
|
* like XSLT
|
||||||
|
*/
|
||||||
|
if (((attr->prefix != NULL) &&
|
||||||
|
(xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
|
||||||
|
((attr->prefix == NULL) &&
|
||||||
|
(xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
|
||||||
|
(ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
|
||||||
|
xmlChar *fulln;
|
||||||
|
|
||||||
|
if (attr->prefix != NULL) {
|
||||||
|
fulln = xmlStrdup(attr->prefix);
|
||||||
|
fulln = xmlStrcat(fulln, BAD_CAST ":");
|
||||||
|
fulln = xmlStrcat(fulln, attr->name);
|
||||||
|
} else {
|
||||||
|
fulln = xmlStrdup(attr->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check that the attribute is not declared in the
|
||||||
|
* serialization
|
||||||
|
*/
|
||||||
|
att = NULL;
|
||||||
|
if (atts != NULL) {
|
||||||
|
i = 0;
|
||||||
|
att = atts[i];
|
||||||
|
while (att != NULL) {
|
||||||
|
if (xmlStrEqual(att, fulln))
|
||||||
|
break;
|
||||||
|
i += 2;
|
||||||
|
att = atts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (att == NULL)
|
||||||
|
attribute(ctxt, fulln, attr->defaultValue);
|
||||||
|
xmlFree(fulln);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attr = attr->nexth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* startElement:
|
* startElement:
|
||||||
* @ctx: the user data (XML parser context)
|
* @ctx: the user data (XML parser context)
|
||||||
@ -1085,71 +1206,12 @@ startElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
|
|||||||
if ((!ctxt->html) &&
|
if ((!ctxt->html) &&
|
||||||
((ctxt->myDoc->intSubset != NULL) ||
|
((ctxt->myDoc->intSubset != NULL) ||
|
||||||
(ctxt->myDoc->extSubset != NULL))) {
|
(ctxt->myDoc->extSubset != NULL))) {
|
||||||
xmlElementPtr elemDecl = NULL;
|
if (ctxt->myDoc->intSubset != NULL)
|
||||||
|
xmlCheckDefaultedAttributesFromDtd(ctxt, ctxt->myDoc->intSubset,
|
||||||
if (prefix != NULL) {
|
name, prefix, atts);
|
||||||
if (ctxt->myDoc->intSubset != NULL)
|
if (ctxt->myDoc->extSubset != NULL)
|
||||||
elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset,
|
xmlCheckDefaultedAttributesFromDtd(ctxt, ctxt->myDoc->extSubset,
|
||||||
name, prefix);
|
name, prefix, atts);
|
||||||
if ((elemDecl == NULL) && (ctxt->myDoc->extSubset != NULL))
|
|
||||||
elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
|
|
||||||
name, prefix);
|
|
||||||
} else {
|
|
||||||
if (ctxt->myDoc->intSubset != NULL)
|
|
||||||
elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset,
|
|
||||||
name, prefix);
|
|
||||||
if ((elemDecl == NULL) && (ctxt->myDoc->extSubset != NULL))
|
|
||||||
elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
|
|
||||||
name, prefix);
|
|
||||||
}
|
|
||||||
if (elemDecl != NULL) {
|
|
||||||
xmlAttributePtr attr = elemDecl->attributes;
|
|
||||||
while (attr != NULL) {
|
|
||||||
if (attr->defaultValue != NULL) {
|
|
||||||
/*
|
|
||||||
* the element should be instantiated in the tree if:
|
|
||||||
* - this is a namespace prefix
|
|
||||||
* - the user required for completion in the tree
|
|
||||||
* like XSLT
|
|
||||||
*/
|
|
||||||
if (((attr->prefix != NULL) &&
|
|
||||||
(xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
|
|
||||||
((attr->prefix == NULL) &&
|
|
||||||
(xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
|
|
||||||
(ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
|
|
||||||
xmlChar *fulln;
|
|
||||||
|
|
||||||
if (attr->prefix != NULL) {
|
|
||||||
fulln = xmlStrdup(attr->prefix);
|
|
||||||
fulln = xmlStrcat(fulln, BAD_CAST ":");
|
|
||||||
fulln = xmlStrcat(fulln, attr->name);
|
|
||||||
} else {
|
|
||||||
fulln = xmlStrdup(attr->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check that the attribute is not declared in the
|
|
||||||
* serialization
|
|
||||||
*/
|
|
||||||
att = NULL;
|
|
||||||
if (atts != NULL) {
|
|
||||||
i = 0;
|
|
||||||
att = atts[i];
|
|
||||||
while (att != NULL) {
|
|
||||||
if (xmlStrEqual(att, fulln))
|
|
||||||
break;
|
|
||||||
i += 2;
|
|
||||||
att = atts[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (att == NULL)
|
|
||||||
attribute(ctxt, fulln, attr->defaultValue);
|
|
||||||
xmlFree(fulln);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attr = attr->nexth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
sys.path.append("python")
|
sys.path.append("python")
|
||||||
@ -358,6 +359,8 @@ profile = testsuite.prop('PROFILE')
|
|||||||
if profile != None:
|
if profile != None:
|
||||||
print profile
|
print profile
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
case = testsuite.children
|
case = testsuite.children
|
||||||
while case != None:
|
while case != None:
|
||||||
global test_nr
|
global test_nr
|
||||||
@ -379,5 +382,5 @@ while case != None:
|
|||||||
conf.freeDoc()
|
conf.freeDoc()
|
||||||
log.close()
|
log.close()
|
||||||
|
|
||||||
print "Ran %d tests: %d suceeded, %d failed and %d generated an error" % (
|
print "Ran %d tests: %d suceeded, %d failed and %d generated an error in %.2f s." % (
|
||||||
test_nr, test_succeed, test_failed, test_error)
|
test_nr, test_succeed, test_failed, test_error, time.time() - start)
|
||||||
|
1
parser.c
1
parser.c
@ -6246,6 +6246,7 @@ xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **value) {
|
|||||||
xmlChar *name, *val;
|
xmlChar *name, *val;
|
||||||
|
|
||||||
*value = NULL;
|
*value = NULL;
|
||||||
|
GROW;
|
||||||
name = xmlParseName(ctxt);
|
name = xmlParseName(ctxt);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
ctxt->errNo = XML_ERR_NAME_REQUIRED;
|
ctxt->errNo = XML_ERR_NAME_REQUIRED;
|
||||||
|
@ -1733,8 +1733,23 @@ xmlSwitchToEncoding(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler)
|
|||||||
if (ctxt->input != NULL) {
|
if (ctxt->input != NULL) {
|
||||||
if (ctxt->input->buf != NULL) {
|
if (ctxt->input->buf != NULL) {
|
||||||
if (ctxt->input->buf->encoder != NULL) {
|
if (ctxt->input->buf->encoder != NULL) {
|
||||||
|
/*
|
||||||
|
* Check in case the auto encoding detetection triggered
|
||||||
|
* in already.
|
||||||
|
*/
|
||||||
if (ctxt->input->buf->encoder == handler)
|
if (ctxt->input->buf->encoder == handler)
|
||||||
return(0);
|
return(0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "UTF-16" can be used for both LE and BE
|
||||||
|
*/
|
||||||
|
if ((!xmlStrncmp(BAD_CAST ctxt->input->buf->encoder->name,
|
||||||
|
BAD_CAST "UTF-16", 6)) &&
|
||||||
|
(!xmlStrncmp(BAD_CAST handler->name,
|
||||||
|
BAD_CAST "UTF-16", 6))) {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: this is a bit dangerous, but that's what it
|
* Note: this is a bit dangerous, but that's what it
|
||||||
* takes to use nearly compatible signature for different
|
* takes to use nearly compatible signature for different
|
||||||
|
46
valid.c
46
valid.c
@ -2892,6 +2892,18 @@ xmlValidateAttributeValue2(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
|
|||||||
xmlEntityPtr ent;
|
xmlEntityPtr ent;
|
||||||
|
|
||||||
ent = xmlGetDocEntity(doc, value);
|
ent = xmlGetDocEntity(doc, value);
|
||||||
|
if ((ent == NULL) && (doc->standalone == 1)) {
|
||||||
|
doc->standalone = 0;
|
||||||
|
ent = xmlGetDocEntity(doc, value);
|
||||||
|
if (ent != NULL) {
|
||||||
|
VERROR(ctxt->userData,
|
||||||
|
"standalone problem: attribute %s reference entity \"%s\" in external subset\n",
|
||||||
|
name, value);
|
||||||
|
/* WAIT to get answer from the Core WG on this
|
||||||
|
ret = 0;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ent == NULL) {
|
if (ent == NULL) {
|
||||||
VERROR(ctxt->userData,
|
VERROR(ctxt->userData,
|
||||||
"ENTITY attribute %s reference an unknown entity \"%s\"\n",
|
"ENTITY attribute %s reference an unknown entity \"%s\"\n",
|
||||||
@ -4797,12 +4809,12 @@ xmlValidateNotationCallback(xmlEntityPtr cur, xmlValidCtxtPtr ctxt,
|
|||||||
if (cur->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
|
if (cur->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
|
||||||
xmlChar *notation = cur->content;
|
xmlChar *notation = cur->content;
|
||||||
|
|
||||||
if (cur != NULL) {
|
if (notation != NULL) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = xmlValidateNotationUse(ctxt, cur->doc, notation);
|
ret = xmlValidateNotationUse(ctxt, cur->doc, notation);
|
||||||
if (ret != 1) {
|
if (ret != 1) {
|
||||||
ctxt->valid = -1;
|
ctxt->valid = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4812,6 +4824,8 @@ static void
|
|||||||
xmlValidateAttributeCallback(xmlAttributePtr cur, xmlValidCtxtPtr ctxt,
|
xmlValidateAttributeCallback(xmlAttributePtr cur, xmlValidCtxtPtr ctxt,
|
||||||
const xmlChar *name ATTRIBUTE_UNUSED) {
|
const xmlChar *name ATTRIBUTE_UNUSED) {
|
||||||
int ret;
|
int ret;
|
||||||
|
xmlDocPtr doc;
|
||||||
|
xmlElementPtr elem;
|
||||||
|
|
||||||
if (cur == NULL)
|
if (cur == NULL)
|
||||||
return;
|
return;
|
||||||
@ -4845,6 +4859,30 @@ xmlValidateAttributeCallback(xmlAttributePtr cur, xmlValidCtxtPtr ctxt,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cur->atype == XML_ATTRIBUTE_NOTATION) {
|
||||||
|
doc = cur->doc;
|
||||||
|
if ((doc == NULL) || (cur->elem == NULL)) {
|
||||||
|
VERROR(ctxt->userData,
|
||||||
|
"xmlValidateAttributeCallback(%s): internal error\n",
|
||||||
|
cur->name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
elem = xmlGetDtdElementDesc(doc->intSubset, cur->elem);
|
||||||
|
if (elem == NULL)
|
||||||
|
elem = xmlGetDtdElementDesc(doc->extSubset, cur->elem);
|
||||||
|
if (elem == NULL) {
|
||||||
|
VERROR(ctxt->userData,
|
||||||
|
"attribute %s: could not find decl for element %s\n",
|
||||||
|
cur->name, cur->elem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (elem->etype == XML_ELEMENT_TYPE_EMPTY) {
|
||||||
|
VERROR(ctxt->userData,
|
||||||
|
"NOTATION attribute %s declared on EMPTY element %s\n",
|
||||||
|
cur->name, cur->elem);
|
||||||
|
ctxt->valid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4879,6 +4917,8 @@ xmlValidateDtdFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
|
|||||||
if ((dtd != NULL) && (dtd->attributes != NULL)) {
|
if ((dtd != NULL) && (dtd->attributes != NULL)) {
|
||||||
table = (xmlAttributeTablePtr) dtd->attributes;
|
table = (xmlAttributeTablePtr) dtd->attributes;
|
||||||
xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt);
|
xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt);
|
||||||
|
}
|
||||||
|
if ((dtd != NULL) && (dtd->entities != NULL)) {
|
||||||
entities = (xmlEntitiesTablePtr) dtd->entities;
|
entities = (xmlEntitiesTablePtr) dtd->entities;
|
||||||
xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback,
|
xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback,
|
||||||
ctxt);
|
ctxt);
|
||||||
@ -4887,6 +4927,8 @@ xmlValidateDtdFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
|
|||||||
if ((dtd != NULL) && (dtd->attributes != NULL)) {
|
if ((dtd != NULL) && (dtd->attributes != NULL)) {
|
||||||
table = (xmlAttributeTablePtr) dtd->attributes;
|
table = (xmlAttributeTablePtr) dtd->attributes;
|
||||||
xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt);
|
xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt);
|
||||||
|
}
|
||||||
|
if ((dtd != NULL) && (dtd->entities != NULL)) {
|
||||||
entities = (xmlEntitiesTablePtr) dtd->entities;
|
entities = (xmlEntitiesTablePtr) dtd->entities;
|
||||||
xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback,
|
xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback,
|
||||||
ctxt);
|
ctxt);
|
||||||
|
Reference in New Issue
Block a user