mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
encoding: Restore old lookup order in xmlOpenCharEncodingHandler
When looking up encodings with xmlLookupCharEncodingHandler, the
returned handler can have a different name than requested
(capitalization, internal aliases). This should eventually be fixed.
For now we revert part of commit 5b893fa9, start the lookup with
xmlFindHandler and add an explicit check for UTF-8.
Should fix the encoding name issue mentioned in #749.
This commit is contained in:
36
encoding.c
36
encoding.c
@@ -1161,7 +1161,7 @@ xmlParseCharEncoding(const char* name)
|
|||||||
if (!strcmp(upper, "SHIFT_JIS")) return(XML_CHAR_ENCODING_SHIFT_JIS);
|
if (!strcmp(upper, "SHIFT_JIS")) return(XML_CHAR_ENCODING_SHIFT_JIS);
|
||||||
if (!strcmp(upper, "EUC-JP")) return(XML_CHAR_ENCODING_EUC_JP);
|
if (!strcmp(upper, "EUC-JP")) return(XML_CHAR_ENCODING_EUC_JP);
|
||||||
|
|
||||||
return(XML_CHAR_ENCODING_NONE);
|
return(XML_CHAR_ENCODING_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1936,7 +1936,9 @@ int
|
|||||||
xmlOpenCharEncodingHandler(const char *name, int output,
|
xmlOpenCharEncodingHandler(const char *name, int output,
|
||||||
xmlCharEncodingHandler **out) {
|
xmlCharEncodingHandler **out) {
|
||||||
const char *nalias;
|
const char *nalias;
|
||||||
|
const char *norig;
|
||||||
xmlCharEncoding enc;
|
xmlCharEncoding enc;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
return(XML_ERR_ARGUMENT);
|
return(XML_ERR_ARGUMENT);
|
||||||
@@ -1945,30 +1947,32 @@ xmlOpenCharEncodingHandler(const char *name, int output,
|
|||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
return(XML_ERR_ARGUMENT);
|
return(XML_ERR_ARGUMENT);
|
||||||
|
|
||||||
|
if ((xmlStrcasecmp(BAD_CAST name, BAD_CAST "UTF-8") == 0) ||
|
||||||
|
(xmlStrcasecmp(BAD_CAST name, BAD_CAST "UTF8") == 0))
|
||||||
|
return(XML_ERR_OK);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do the alias resolution
|
* Do the alias resolution
|
||||||
*/
|
*/
|
||||||
|
norig = name;
|
||||||
nalias = xmlGetEncodingAlias(name);
|
nalias = xmlGetEncodingAlias(name);
|
||||||
if (nalias != NULL)
|
if (nalias != NULL)
|
||||||
name = nalias;
|
name = nalias;
|
||||||
|
|
||||||
|
ret = xmlFindHandler(name, output, out);
|
||||||
|
if (*out != NULL)
|
||||||
|
return(0);
|
||||||
|
if (ret != XML_ERR_UNSUPPORTED_ENCODING)
|
||||||
|
return(ret);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* UTF-16 needs the built-in handler which is only available via
|
* Fallback using the canonical names
|
||||||
* xmlFindHandler.
|
*
|
||||||
|
* TODO: We should make sure that the name of the returned
|
||||||
|
* handler equals norig.
|
||||||
*/
|
*/
|
||||||
if (xmlStrcasecmp(BAD_CAST name, BAD_CAST "UTF16") == 0) {
|
enc = xmlParseCharEncoding(norig);
|
||||||
name = "UTF-16";
|
return(xmlLookupCharEncodingHandler(enc, out));
|
||||||
} else if (xmlStrcasecmp(BAD_CAST name, BAD_CAST "UTF-16") != 0) {
|
|
||||||
enc = xmlParseCharEncoding(name);
|
|
||||||
if (enc != XML_CHAR_ENCODING_NONE) {
|
|
||||||
int res = xmlLookupCharEncodingHandler(enc, out);
|
|
||||||
|
|
||||||
if (res != XML_ERR_UNSUPPORTED_ENCODING)
|
|
||||||
return(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(xmlFindHandler(name, output, out));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ testUnsupportedEncoding(void) {
|
|||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
|
|
||||||
error = xmlGetLastError();
|
error = xmlGetLastError();
|
||||||
if (error->code != XML_ERR_UNSUPPORTED_ENCODING ||
|
if (error == NULL ||
|
||||||
|
error->code != XML_ERR_UNSUPPORTED_ENCODING ||
|
||||||
error->level != XML_ERR_WARNING ||
|
error->level != XML_ERR_WARNING ||
|
||||||
strcmp(error->message, "Unsupported encoding: #unsupported\n") != 0)
|
strcmp(error->message, "Unsupported encoding: #unsupported\n") != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user