From 878eab04c07a090c7b3aeb182993b579e0ea0195 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 19 Feb 2002 13:46:09 +0000 Subject: [PATCH] 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 --- ChangeLog | 5 ++ SAX.c | 192 ++++++++++++++++++++++++++-------------- check-xml-test-suite.py | 7 +- parser.c | 1 + parserInternals.c | 15 ++++ valid.c | 46 +++++++++- 6 files changed, 197 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index ac41b809..4941a810 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Feb 19 14:44:53 CET 2002 Daniel Veillard + + * 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 * parser.c valid.c: a couple of errors were reported but not diff --git a/SAX.c b/SAX.c index 5604caf9..cbf21cf2 100644 --- a/SAX.c +++ b/SAX.c @@ -979,6 +979,127 @@ attribute(void *ctx, const xmlChar *fullname, const xmlChar *value) 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: * @ctx: the user data (XML parser context) @@ -1085,71 +1206,12 @@ startElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) if ((!ctxt->html) && ((ctxt->myDoc->intSubset != NULL) || (ctxt->myDoc->extSubset != NULL))) { - xmlElementPtr elemDecl = NULL; - - if (prefix != NULL) { - 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); - } 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; - } - } + if (ctxt->myDoc->intSubset != NULL) + xmlCheckDefaultedAttributesFromDtd(ctxt, ctxt->myDoc->intSubset, + name, prefix, atts); + if (ctxt->myDoc->extSubset != NULL) + xmlCheckDefaultedAttributesFromDtd(ctxt, ctxt->myDoc->extSubset, + name, prefix, atts); } /* diff --git a/check-xml-test-suite.py b/check-xml-test-suite.py index 248367d4..1929b70e 100755 --- a/check-xml-test-suite.py +++ b/check-xml-test-suite.py @@ -1,5 +1,6 @@ #!/usr/bin/python import sys +import time import os import string sys.path.append("python") @@ -358,6 +359,8 @@ profile = testsuite.prop('PROFILE') if profile != None: print profile +start = time.time() + case = testsuite.children while case != None: global test_nr @@ -379,5 +382,5 @@ while case != None: conf.freeDoc() log.close() -print "Ran %d tests: %d suceeded, %d failed and %d generated an error" % ( - test_nr, test_succeed, test_failed, test_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, time.time() - start) diff --git a/parser.c b/parser.c index 9162d900..6d6df5b8 100644 --- a/parser.c +++ b/parser.c @@ -6246,6 +6246,7 @@ xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **value) { xmlChar *name, *val; *value = NULL; + GROW; name = xmlParseName(ctxt); if (name == NULL) { ctxt->errNo = XML_ERR_NAME_REQUIRED; diff --git a/parserInternals.c b/parserInternals.c index cdf8dcb1..c539714d 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -1733,8 +1733,23 @@ xmlSwitchToEncoding(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler) if (ctxt->input != NULL) { if (ctxt->input->buf != NULL) { if (ctxt->input->buf->encoder != NULL) { + /* + * Check in case the auto encoding detetection triggered + * in already. + */ if (ctxt->input->buf->encoder == handler) 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 * takes to use nearly compatible signature for different diff --git a/valid.c b/valid.c index de596e41..7be1a4ae 100644 --- a/valid.c +++ b/valid.c @@ -2892,6 +2892,18 @@ xmlValidateAttributeValue2(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlEntityPtr ent; 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) { VERROR(ctxt->userData, "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) { xmlChar *notation = cur->content; - if (cur != NULL) { + if (notation != NULL) { int ret; ret = xmlValidateNotationUse(ctxt, cur->doc, notation); if (ret != 1) { - ctxt->valid = -1; + ctxt->valid = 0; } } } @@ -4812,6 +4824,8 @@ static void xmlValidateAttributeCallback(xmlAttributePtr cur, xmlValidCtxtPtr ctxt, const xmlChar *name ATTRIBUTE_UNUSED) { int ret; + xmlDocPtr doc; + xmlElementPtr elem; if (cur == NULL) 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)) { table = (xmlAttributeTablePtr) dtd->attributes; xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt); + } + if ((dtd != NULL) && (dtd->entities != NULL)) { entities = (xmlEntitiesTablePtr) dtd->entities; xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback, ctxt); @@ -4887,6 +4927,8 @@ xmlValidateDtdFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { if ((dtd != NULL) && (dtd->attributes != NULL)) { table = (xmlAttributeTablePtr) dtd->attributes; xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt); + } + if ((dtd != NULL) && (dtd->entities != NULL)) { entities = (xmlEntitiesTablePtr) dtd->entities; xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback, ctxt);