@@ -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.
@@ -1979,6 +1984,14 @@ xmlCharEncodingHandlerPtr
19791984xmlFindCharEncodingHandler (const char * name ) {
19801985 xmlCharEncodingHandler * ret ;
19811986
1987+ /*
1988+ * This handler shouldn't be used, but we must return a non-NULL
1989+ * handler.
1990+ */
1991+ if ((xmlStrcasecmp (BAD_CAST name , BAD_CAST "UTF-8" ) == 0 ) ||
1992+ (xmlStrcasecmp (BAD_CAST name , BAD_CAST "UTF8" ) == 0 ))
1993+ return ((xmlCharEncodingHandlerPtr ) & xmlUTF8Handler );
1994+
19821995 xmlOpenCharEncodingHandler (name , 0 , & ret );
19831996 return (ret );
19841997}
0 commit comments