Skip to content

Commit

Permalink
parser: Consolidate error handling for undeclared entities
Browse files Browse the repository at this point in the history
Always use XML_WAR_UNDECLARED_ENTITY with warning error level in
documents with external subset or parameter entities. Use
XML_ERR_UNDECLARED_ENTITY otherwise.
  • Loading branch information
nwellnhof committed Apr 23, 2024
1 parent 00336f0 commit b717abd
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 20 deletions.
6 changes: 3 additions & 3 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/tests/input_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def my_ctx_error_cb(arg, msg, severity, reserved):
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
Expand All @@ -114,7 +114,7 @@ def my_ctx_error_cb(arg, msg, severity, reserved):
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
Expand Down
2 changes: 1 addition & 1 deletion result/ent7.sax
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xmlSAXUserParseFile returned error 27
xmlParseDocument returned error 26
SAX.setDocumentLocator()
SAX.startDocument()
SAX.internalSubset(item, , )
Expand Down
2 changes: 1 addition & 1 deletion result/ent7.sax2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xmlSAXUserParseFile returned error 27
xmlParseDocument returned error 26
SAX.setDocumentLocator()
SAX.startDocument()
SAX.internalSubset(item, , )
Expand Down
2 changes: 1 addition & 1 deletion result/errors/rec_att_default.xml.ent
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion result/errors/rec_att_default.xml.err
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion result/errors/rec_att_default.xml.str
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion result/noent/ent7.sax2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xmlSAXUserParseFile returned error 27
xmlParseDocument returned error 26
SAX.setDocumentLocator()
SAX.startDocument()
SAX.internalSubset(item, , )
Expand Down
2 changes: 1 addition & 1 deletion result/noent/xml2.sax2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xmlSAXUserParseFile returned error 27
xmlParseDocument returned error 26
SAX.setDocumentLocator()
SAX.startDocument()
SAX.internalSubset(test, , )
Expand Down
2 changes: 1 addition & 1 deletion result/xml2.sax
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xmlSAXUserParseFile returned error 27
xmlParseDocument returned error 26
SAX.setDocumentLocator()
SAX.startDocument()
SAX.internalSubset(test, , )
Expand Down
2 changes: 1 addition & 1 deletion result/xml2.sax2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xmlSAXUserParseFile returned error 27
xmlParseDocument returned error 26
SAX.setDocumentLocator()
SAX.startDocument()
SAX.internalSubset(test, , )
Expand Down
8 changes: 2 additions & 6 deletions runtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b717abd

Please sign in to comment.