@@ -1279,9 +1279,8 @@ DECLARE_ISO_FUNCS(16)
12791279 { (char *) name, in, out EMPTY_ICONV EMPTY_UCONV }
12801280
12811281static const xmlCharEncodingHandler defaultHandlers [] = {
1282- MAKE_HANDLER ("UTF-8" , UTF8ToUTF8 , UTF8ToUTF8 )
12831282#ifdef LIBXML_OUTPUT_ENABLED
1284- , MAKE_HANDLER ("UTF-16LE" , UTF16LEToUTF8 , UTF8ToUTF16LE )
1283+ MAKE_HANDLER ("UTF-16LE" , UTF16LEToUTF8 , UTF8ToUTF16LE )
12851284 ,MAKE_HANDLER ("UTF-16BE" , UTF16BEToUTF8 , UTF8ToUTF16BE )
12861285 ,MAKE_HANDLER ("UTF-16" , UTF16LEToUTF8 , UTF8ToUTF16 )
12871286 ,MAKE_HANDLER ("ISO-8859-1" , isolat1ToUTF8 , UTF8Toisolat1 )
@@ -1291,7 +1290,7 @@ static const xmlCharEncodingHandler defaultHandlers[] = {
12911290 ,MAKE_HANDLER ("HTML" , NULL , UTF8ToHtml )
12921291#endif
12931292#else
1294- , MAKE_HANDLER ("UTF-16LE" , UTF16LEToUTF8 , NULL )
1293+ MAKE_HANDLER ("UTF-16LE" , UTF16LEToUTF8 , NULL )
12951294 ,MAKE_HANDLER ("UTF-16BE" , UTF16BEToUTF8 , NULL )
12961295 ,MAKE_HANDLER ("UTF-16" , UTF16LEToUTF8 , NULL )
12971296 ,MAKE_HANDLER ("ISO-8859-1" , isolat1ToUTF8 , NULL )
@@ -1321,10 +1320,13 @@ static const xmlCharEncodingHandler defaultHandlers[] = {
13211320#define NUM_DEFAULT_HANDLERS \
13221321 (sizeof(defaultHandlers) / sizeof(defaultHandlers[0]))
13231322
1324- static const xmlCharEncodingHandler * xmlUTF16LEHandler = & defaultHandlers [1 ];
1325- static const xmlCharEncodingHandler * xmlUTF16BEHandler = & defaultHandlers [2 ];
1326- static const xmlCharEncodingHandler * xmlLatin1Handler = & defaultHandlers [4 ];
1327- static const xmlCharEncodingHandler * xmlAsciiHandler = & defaultHandlers [5 ];
1323+ static const xmlCharEncodingHandler xmlUTF8Handler =
1324+ MAKE_HANDLER ("UTF-8" , UTF8ToUTF8 , UTF8ToUTF8 );
1325+
1326+ static const xmlCharEncodingHandler * xmlUTF16LEHandler = & defaultHandlers [0 ];
1327+ static const xmlCharEncodingHandler * xmlUTF16BEHandler = & defaultHandlers [1 ];
1328+ static const xmlCharEncodingHandler * xmlLatin1Handler = & defaultHandlers [3 ];
1329+ static const xmlCharEncodingHandler * xmlAsciiHandler = & defaultHandlers [4 ];
13281330
13291331/* the size should be growable, but it's not a big deal ... */
13301332#define MAX_ENCODING_HANDLERS 50
@@ -1922,6 +1924,9 @@ xmlGetCharEncodingHandler(xmlCharEncoding enc) {
19221924 *
19231925 * The handler must be closed with xmlCharEncCloseFunc.
19241926 *
1927+ * If the encoding is UTF-8, a NULL handler and no error code will
1928+ * be returned.
1929+ *
19251930 * Available since 2.13.0.
19261931 *
19271932 * Returns an xmlParserErrors error code.
@@ -1941,6 +1946,10 @@ xmlOpenCharEncodingHandler(const char *name, int output,
19411946 if (name == NULL )
19421947 return (XML_ERR_ARGUMENT );
19431948
1949+ if ((xmlStrcasecmp (BAD_CAST name , BAD_CAST "UTF-8" ) == 0 ) ||
1950+ (xmlStrcasecmp (BAD_CAST name , BAD_CAST "UTF8" ) == 0 ))
1951+ return (XML_ERR_OK );
1952+
19441953 /*
19451954 * Do the alias resolution
19461955 */
@@ -1957,6 +1966,9 @@ xmlOpenCharEncodingHandler(const char *name, int output,
19571966
19581967 /*
19591968 * Fallback using the canonical names
1969+ *
1970+ * TODO: We should make sure that the name of the returned
1971+ * handler equals norig.
19601972 */
19611973 enc = xmlParseCharEncoding (norig );
19621974 return (xmlLookupCharEncodingHandler (enc , out ));
@@ -1976,6 +1988,14 @@ xmlCharEncodingHandlerPtr
19761988xmlFindCharEncodingHandler (const char * name ) {
19771989 xmlCharEncodingHandler * ret ;
19781990
1991+ /*
1992+ * This handler shouldn't be used, but we must return a non-NULL
1993+ * handler.
1994+ */
1995+ if ((xmlStrcasecmp (BAD_CAST name , BAD_CAST "UTF-8" ) == 0 ) ||
1996+ (xmlStrcasecmp (BAD_CAST name , BAD_CAST "UTF8" ) == 0 ))
1997+ return ((xmlCharEncodingHandlerPtr ) & xmlUTF8Handler );
1998+
19791999 xmlOpenCharEncodingHandler (name , 0 , & ret );
19802000 return (ret );
19812001}
0 commit comments