diff --git a/ChangeLog b/ChangeLog index afbbf14e..44c96bf7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Feb 18 19:27:32 CET 2002 Daniel Veillard + + * SAX.c parserInternals.c valid.c: more work on the conformance + suite. Took the step to finally block documents with encoding + errors. It's a fatal error per the spec, people should have fixed + their documents by now. + Mon Feb 18 15:30:14 CET 2002 Daniel Veillard * check-xml-test-suite.py: fixed the test script after some discussion diff --git a/SAX.c b/SAX.c index ae31245e..5604caf9 100644 --- a/SAX.c +++ b/SAX.c @@ -640,6 +640,8 @@ unparsedEntityDecl(void *ctx, const xmlChar *name, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", name, publicId, systemId, notationName); #endif +#if 0 + Done in xmlValidateDtdFinal now. if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc) { int ret; ret = xmlValidateNotationUse(&ctxt->vctxt, ctxt->myDoc, @@ -649,6 +651,7 @@ unparsedEntityDecl(void *ctx, const xmlChar *name, ctxt->valid = 0; } } +#endif if (ctxt->inSubset == 1) { ent = xmlAddDocEntity(ctxt->myDoc, name, XML_EXTERNAL_GENERAL_UNPARSED_ENTITY, @@ -1220,7 +1223,13 @@ startElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) * check the document root element for validity */ if ((ctxt->validate) && (ctxt->vctxt.finishDtd == 0)) { - ctxt->valid &= xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc); + int chk; + + chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc); + if (chk <= 0) + ctxt->valid = 0; + if (chk < 0) + ctxt->wellFormed = 0; ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); ctxt->vctxt.finishDtd = 1; } diff --git a/parserInternals.c b/parserInternals.c index a155bdc3..16759ec2 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -1228,6 +1228,7 @@ encoding_error: ctxt->input->cur[0], ctxt->input->cur[1], ctxt->input->cur[2], ctxt->input->cur[3]); } + ctxt->wellFormed = 0; ctxt->errNo = XML_ERR_INVALID_ENCODING; ctxt->charset = XML_CHAR_ENCODING_8859_1; @@ -1371,6 +1372,7 @@ encoding_error: ctxt->input->cur[0], ctxt->input->cur[1], ctxt->input->cur[2], ctxt->input->cur[3]); } + ctxt->wellFormed = 0; ctxt->errNo = XML_ERR_INVALID_ENCODING; ctxt->charset = XML_CHAR_ENCODING_8859_1; @@ -1481,6 +1483,7 @@ encoding_error: ctxt->input->cur[2], ctxt->input->cur[3]); } ctxt->errNo = XML_ERR_INVALID_ENCODING; + ctxt->wellFormed = 0; } *len = 1; diff --git a/valid.c b/valid.c index 32357551..ba1ffdf6 100644 --- a/valid.c +++ b/valid.c @@ -4788,9 +4788,30 @@ xmlValidateDtd(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlDtdPtr dtd) { return(ret); } +static void +xmlValidateNotationCallback(xmlEntityPtr cur, xmlValidCtxtPtr ctxt, + const xmlChar *name ATTRIBUTE_UNUSED) { + if (cur == NULL) + return; + if (cur->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { + xmlChar *notation = cur->content; + + if (cur != NULL) { + int ret; + + ret = xmlValidateNotationUse(ctxt, cur->doc, notation); + if (ret != 1) { + ctxt->valid = -1; + } + } + } +} + static void xmlValidateAttributeCallback(xmlAttributePtr cur, xmlValidCtxtPtr ctxt, const xmlChar *name ATTRIBUTE_UNUSED) { + int ret; + if (cur == NULL) return; switch (cur->atype) { @@ -4806,14 +4827,19 @@ xmlValidateAttributeCallback(xmlAttributePtr cur, xmlValidCtxtPtr ctxt, case XML_ATTRIBUTE_ENTITIES: case XML_ATTRIBUTE_NOTATION: if (cur->defaultValue != NULL) { - ctxt->valid &= xmlValidateAttributeValue2(ctxt, ctxt->doc, - cur->name, cur->atype, cur->defaultValue); + + ret = xmlValidateAttributeValue2(ctxt, ctxt->doc, cur->name, + cur->atype, cur->defaultValue); + if ((ret == 0) && (ctxt->valid == 1)) + ctxt->valid = 0; } if (cur->tree != NULL) { xmlEnumerationPtr tree = cur->tree; while (tree != NULL) { - ctxt->valid &= xmlValidateAttributeValue2(ctxt, ctxt->doc, + ret = xmlValidateAttributeValue2(ctxt, ctxt->doc, cur->name, cur->atype, tree->name); + if ((ret == 0) && (ctxt->valid == 1)) + ctxt->valid = 0; tree = tree->next; } } @@ -4834,29 +4860,35 @@ xmlValidateAttributeCallback(xmlAttributePtr cur, xmlValidCtxtPtr ctxt, * - check that NOTATION type attributes default or * possible values matches one of the defined notations. * - * returns 1 if valid or 0 otherwise + * returns 1 if valid or 0 if invalid and -1 if not well-formed */ int xmlValidateDtdFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { - int ret = 1; xmlDtdPtr dtd; xmlAttributeTablePtr table; + xmlEntitiesTablePtr entities; if (doc == NULL) return(0); if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) return(0); ctxt->doc = doc; - ctxt->valid = ret; + ctxt->valid = 1; dtd = doc->intSubset; if ((dtd != NULL) && (dtd->attributes != NULL)) { table = (xmlAttributeTablePtr) dtd->attributes; xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt); + entities = (xmlEntitiesTablePtr) dtd->entities; + xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback, + ctxt); } dtd = doc->extSubset; if ((dtd != NULL) && (dtd->attributes != NULL)) { table = (xmlAttributeTablePtr) dtd->attributes; xmlHashScan(table, (xmlHashScanner) xmlValidateAttributeCallback, ctxt); + entities = (xmlEntitiesTablePtr) dtd->entities; + xmlHashScan(entities, (xmlHashScanner) xmlValidateNotationCallback, + ctxt); } return(ctxt->valid); }