parser: Fix EBCDIC detection

This commit is contained in:
Nick Wellnhofer 2024-06-28 23:13:38 +02:00
parent 37a9ff11d8
commit 0b0dd98983
2 changed files with 18 additions and 19 deletions

View File

@ -873,7 +873,8 @@ xmlLookupCharEncodingHandler(xmlCharEncoding enc,
return(XML_ERR_UNSUPPORTED_ENCODING);
/* Return NULL handler for UTF-8 */
if (enc == XML_CHAR_ENCODING_UTF8)
if ((enc == XML_CHAR_ENCODING_UTF8) ||
(enc == XML_CHAR_ENCODING_NONE))
return(XML_ERR_OK);
handler = &defaultHandlers[enc];

View File

@ -1205,24 +1205,9 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
if ((ctxt == NULL) || (ctxt->input == NULL))
return(-1);
switch (enc) {
case XML_CHAR_ENCODING_NONE:
case XML_CHAR_ENCODING_UTF8:
case XML_CHAR_ENCODING_ASCII:
res = 0;
break;
case XML_CHAR_ENCODING_EBCDIC:
res = xmlDetectEBCDIC(ctxt, &handler);
break;
default:
res = xmlLookupCharEncodingHandler(enc, &handler);
break;
}
res = xmlLookupCharEncodingHandler(enc, &handler);
if (res != 0) {
const char *name = xmlGetCharEncodingName(enc);
xmlFatalErr(ctxt, res, (name ? name : "<null>"));
xmlFatalErr(ctxt, res, NULL);
return(-1);
}
@ -1512,7 +1497,20 @@ xmlDetectEncoding(xmlParserCtxtPtr ctxt) {
if (enc != XML_CHAR_ENCODING_NONE) {
ctxt->input->flags |= autoFlag;
xmlSwitchEncoding(ctxt, enc);
if (enc == XML_CHAR_ENCODING_EBCDIC) {
xmlCharEncodingHandlerPtr handler;
int res;
res = xmlDetectEBCDIC(ctxt, &handler);
if (res != XML_ERR_OK) {
xmlFatalErr(ctxt, res, "detecting EBCDIC\n");
} else {
xmlSwitchInputEncoding(ctxt, ctxt->input, handler);
}
} else {
xmlSwitchEncoding(ctxt, enc);
}
}
}