mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-21 14:53:44 +03:00
parser: Consolidate error handling for undeclared entities
Always use XML_WAR_UNDECLARED_ENTITY with warning error level in documents with external subset or parameter entities. Use XML_ERR_UNDECLARED_ENTITY otherwise.
This commit is contained in:
6
parser.c
6
parser.c
@@ -7600,8 +7600,8 @@ xmlLookupGeneralEntity(xmlParserCtxtPtr ctxt, const xmlChar *name, int inAttr) {
|
||||
xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
|
||||
"Entity '%s' not defined\n", name);
|
||||
} else {
|
||||
xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY,
|
||||
"Entity '%s' not defined\n", name);
|
||||
xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
|
||||
"Entity '%s' not defined\n", name, NULL);
|
||||
if ((ctxt->inSubset == 0) &&
|
||||
(ctxt->sax != NULL) &&
|
||||
(ctxt->disableSAX == 0) &&
|
||||
@@ -7844,7 +7844,7 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)
|
||||
* precede any reference to it...
|
||||
*/
|
||||
if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) {
|
||||
xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY,
|
||||
xmlValidityError(ctxt, XML_ERR_UNDECLARED_ENTITY,
|
||||
"PEReference: %%%s; not found\n",
|
||||
name, NULL);
|
||||
} else
|
||||
|
@@ -101,7 +101,7 @@ run_test(desc="Loading entity with custom callback",
|
||||
exp_status="loaded", exp_err=[
|
||||
( 3, 'failed to load "http://example.com/dtds/sample.dtd": Attempt to load network entity\n'),
|
||||
( -1, "Attempt to load network entity: http://example.com/dtds/sample.dtd"),
|
||||
( 4, "Entity 'sample.entity' not defined\n")
|
||||
( 3, "Entity 'sample.entity' not defined\n")
|
||||
])
|
||||
|
||||
# Register a catalog (also accessible via pystr://) and retry
|
||||
@@ -114,7 +114,7 @@ run_test(desc="Loading entity and unregistering callback",
|
||||
test_callback=lambda: libxml2.popInputCallbacks(),
|
||||
exp_status="loaded", exp_err=[
|
||||
( 3, "failed to load \"py://strings/dtds/sample.dtd\": No such file or directory\n"),
|
||||
( 4, "Entity 'sample.entity' not defined\n")
|
||||
( 3, "Entity 'sample.entity' not defined\n")
|
||||
])
|
||||
|
||||
# Try to load the document again
|
||||
|
@@ -1,4 +1,4 @@
|
||||
xmlSAXUserParseFile returned error 27
|
||||
xmlParseDocument returned error 26
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.internalSubset(item, , )
|
||||
|
@@ -1,4 +1,4 @@
|
||||
xmlSAXUserParseFile returned error 27
|
||||
xmlParseDocument returned error 26
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.internalSubset(item, , )
|
||||
|
@@ -1,4 +1,4 @@
|
||||
./test/errors/rec_att_default.xml:3: parser error : Entity 'b' not defined
|
||||
./test/errors/rec_att_default.xml:3: parser warning : Entity 'b' not defined
|
||||
<!ATTLIST x y CDATA "&a;">
|
||||
^
|
||||
./test/errors/rec_att_default.xml:6: parser error : Detected an entity reference loop
|
||||
|
@@ -1,4 +1,4 @@
|
||||
./test/errors/rec_att_default.xml:3: parser error : Entity 'b' not defined
|
||||
./test/errors/rec_att_default.xml:3: parser warning : Entity 'b' not defined
|
||||
<!ATTLIST x y CDATA "&a;">
|
||||
^
|
||||
./test/errors/rec_att_default.xml:6: parser error : Detected an entity reference loop
|
||||
|
@@ -1,4 +1,4 @@
|
||||
./test/errors/rec_att_default.xml:3: parser error : Entity 'b' not defined
|
||||
./test/errors/rec_att_default.xml:3: parser warning : Entity 'b' not defined
|
||||
<!ATTLIST x y CDATA "&a;">
|
||||
^
|
||||
./test/errors/rec_att_default.xml:6: parser error : Detected an entity reference loop
|
||||
|
@@ -1,4 +1,4 @@
|
||||
xmlSAXUserParseFile returned error 27
|
||||
xmlParseDocument returned error 26
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.internalSubset(item, , )
|
||||
|
@@ -1,4 +1,4 @@
|
||||
xmlSAXUserParseFile returned error 27
|
||||
xmlParseDocument returned error 26
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.internalSubset(test, , )
|
||||
|
@@ -1,4 +1,4 @@
|
||||
xmlSAXUserParseFile returned error 27
|
||||
xmlParseDocument returned error 26
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.internalSubset(test, , )
|
||||
|
@@ -1,4 +1,4 @@
|
||||
xmlSAXUserParseFile returned error 27
|
||||
xmlParseDocument returned error 26
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.internalSubset(test, , )
|
||||
|
@@ -1515,8 +1515,8 @@ saxParseTest(const char *filename, const char *result,
|
||||
xmlFreeDoc(ctxt->myDoc);
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
}
|
||||
if (ret == XML_WAR_UNDECLARED_ENTITY) {
|
||||
fprintf(SAXdebug, "xmlSAXUserParseFile returned error %d\n", ret);
|
||||
if (ret == XML_ERR_UNDECLARED_ENTITY) {
|
||||
fprintf(SAXdebug, "xmlParseDocument returned error %d\n", ret);
|
||||
ret = 0;
|
||||
}
|
||||
if (ret != 0) {
|
||||
@@ -1556,10 +1556,6 @@ saxParseTest(const char *filename, const char *result,
|
||||
xmlFreeDoc(ctxt->myDoc);
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
}
|
||||
if (ret == XML_WAR_UNDECLARED_ENTITY) {
|
||||
fprintf(SAXdebug, "xmlSAXUserParseFile returned error %d\n", ret);
|
||||
ret = 0;
|
||||
}
|
||||
fclose(SAXdebug);
|
||||
if (compareFiles(temp, result)) {
|
||||
fprintf(stderr, "Got a difference for %s\n", filename);
|
||||
|
Reference in New Issue
Block a user