mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
parser: Fix XML_ERR_UNSUPPORTED_ENCODING errors
Commit 45157261
added the check in the wrong place.
Also allow unsupported encoding in xmlNewInputInternal.
Fixes #654.
This commit is contained in:
3
error.c
3
error.c
@@ -1161,6 +1161,9 @@ xmlErrString(xmlParserErrors code) {
|
|||||||
case XML_ERR_REDECL_PREDEF_ENTITY:
|
case XML_ERR_REDECL_PREDEF_ENTITY:
|
||||||
errmsg = "Invalid redeclaration of predefined entity";
|
errmsg = "Invalid redeclaration of predefined entity";
|
||||||
break;
|
break;
|
||||||
|
case XML_ERR_UNSUPPORTED_ENCODING:
|
||||||
|
errmsg = "Unsupported encoding";
|
||||||
|
break;
|
||||||
|
|
||||||
case XML_IO_UNKNOWN:
|
case XML_IO_UNKNOWN:
|
||||||
errmsg = "Unknown IO error"; break;
|
errmsg = "Unknown IO error"; break;
|
||||||
|
@@ -175,9 +175,7 @@ xmlCtxtErrIO(xmlParserCtxtPtr ctxt, int code, const char *uri)
|
|||||||
if (ctxt == NULL)
|
if (ctxt == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (code == XML_ERR_UNSUPPORTED_ENCODING) {
|
if ((code == XML_IO_ENOENT) ||
|
||||||
level = XML_ERR_WARNING;
|
|
||||||
} else if ((code == XML_IO_ENOENT) ||
|
|
||||||
(code == XML_IO_NETWORK_ATTEMPT) ||
|
(code == XML_IO_NETWORK_ATTEMPT) ||
|
||||||
(code == XML_IO_UNKNOWN)) {
|
(code == XML_IO_UNKNOWN)) {
|
||||||
if (ctxt->validate == 0)
|
if (ctxt->validate == 0)
|
||||||
@@ -318,17 +316,23 @@ xmlCtxtErr(xmlParserCtxtPtr ctxt, xmlNodePtr node, xmlErrorDomain domain,
|
|||||||
* Handle a fatal parser error, i.e. violating Well-Formedness constraints
|
* Handle a fatal parser error, i.e. violating Well-Formedness constraints
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
|
xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors code, const char *info)
|
||||||
{
|
{
|
||||||
const char *errmsg;
|
const char *errmsg;
|
||||||
|
xmlErrorLevel level;
|
||||||
|
|
||||||
errmsg = xmlErrString(error);
|
if (code == XML_ERR_UNSUPPORTED_ENCODING)
|
||||||
|
level = XML_ERR_WARNING;
|
||||||
|
else
|
||||||
|
level = XML_ERR_FATAL;
|
||||||
|
|
||||||
|
errmsg = xmlErrString(code);
|
||||||
|
|
||||||
if (info == NULL) {
|
if (info == NULL) {
|
||||||
xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
|
xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, code, level,
|
||||||
NULL, NULL, NULL, 0, "%s\n", errmsg);
|
NULL, NULL, NULL, 0, "%s\n", errmsg);
|
||||||
} else {
|
} else {
|
||||||
xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
|
xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, code, level,
|
||||||
(const xmlChar *) info, NULL, NULL, 0,
|
(const xmlChar *) info, NULL, NULL, 0,
|
||||||
"%s: %s\n", errmsg, info);
|
"%s: %s\n", errmsg, info);
|
||||||
}
|
}
|
||||||
@@ -1560,12 +1564,8 @@ xmlNewInputInternal(xmlParserCtxtPtr ctxt, xmlParserInputBufferPtr buf,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoding != NULL) {
|
if (encoding != NULL)
|
||||||
if (xmlSwitchInputEncodingName(ctxt, input, encoding) < 0) {
|
xmlSwitchInputEncodingName(ctxt, input, encoding);
|
||||||
xmlFreeInputStream(input);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(input);
|
return(input);
|
||||||
}
|
}
|
||||||
|
29
testparser.c
29
testparser.c
@@ -9,6 +9,34 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
testUnsupportedEncoding(void) {
|
||||||
|
xmlDocPtr doc;
|
||||||
|
const xmlError *error;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
xmlResetLastError();
|
||||||
|
|
||||||
|
doc = xmlReadDoc(BAD_CAST "<doc/>", NULL, "#unsupported",
|
||||||
|
XML_PARSE_NOWARNING);
|
||||||
|
if (doc == NULL) {
|
||||||
|
fprintf(stderr, "xmlReadDoc failed with unsupported encoding\n");
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
|
||||||
|
error = xmlGetLastError();
|
||||||
|
if (error->code != XML_ERR_UNSUPPORTED_ENCODING ||
|
||||||
|
error->level != XML_ERR_WARNING ||
|
||||||
|
strcmp(error->message, "Unsupported encoding: #unsupported\n") != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "xmlReadDoc failed to raise correct error\n");
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef LIBXML_SAX1_ENABLED
|
#ifdef LIBXML_SAX1_ENABLED
|
||||||
static int
|
static int
|
||||||
testBalancedChunk(void) {
|
testBalancedChunk(void) {
|
||||||
@@ -179,6 +207,7 @@ int
|
|||||||
main(void) {
|
main(void) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
err |= testUnsupportedEncoding();
|
||||||
#ifdef LIBXML_SAX1_ENABLED
|
#ifdef LIBXML_SAX1_ENABLED
|
||||||
err |= testBalancedChunk();
|
err |= testBalancedChunk();
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user