more work on the conformance suite. Took the step to finally block
* 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.
Daniel
diff --git a/ChangeLog b/ChangeLog
index afbbf14..44c96bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Feb 18 19:27:32 CET 2002 Daniel Veillard <daniel@veillard.com>
+
+ * 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 <daniel@veillard.com>
* check-xml-test-suite.py: fixed the test script after some discussion
diff --git a/SAX.c b/SAX.c
index ae31245..5604caf 100644
--- a/SAX.c
+++ b/SAX.c
@@ -640,6 +640,8 @@
"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 @@
ctxt->valid = 0;
}
}
+#endif
if (ctxt->inSubset == 1) {
ent = xmlAddDocEntity(ctxt->myDoc, name,
XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
@@ -1220,7 +1223,13 @@
* 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 a155bdc..16759ec 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -1228,6 +1228,7 @@
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 @@
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 @@
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 3235755..ba1ffdf 100644
--- a/valid.c
+++ b/valid.c
@@ -4789,8 +4789,29 @@
}
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 @@
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 @@
* - 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);
}