@@ -364,20 +364,14 @@ void
364364xmlFatalErr (xmlParserCtxtPtr ctxt , xmlParserErrors code , const char * info )
365365{
366366 const char * errmsg ;
367- xmlErrorLevel level ;
368-
369- if (code == XML_ERR_UNSUPPORTED_ENCODING )
370- level = XML_ERR_WARNING ;
371- else
372- level = XML_ERR_FATAL ;
373367
374368 errmsg = xmlErrString (code );
375369
376370 if (info == NULL ) {
377- xmlCtxtErr (ctxt , NULL , XML_FROM_PARSER , code , level ,
371+ xmlCtxtErr (ctxt , NULL , XML_FROM_PARSER , code , XML_ERR_FATAL ,
378372 NULL , NULL , NULL , 0 , "%s\n" , errmsg );
379373 } else {
380- xmlCtxtErr (ctxt , NULL , XML_FROM_PARSER , code , level ,
374+ xmlCtxtErr (ctxt , NULL , XML_FROM_PARSER , code , XML_ERR_FATAL ,
381375 (const xmlChar * ) info , NULL , NULL , 0 ,
382376 "%s: %s\n" , errmsg , info );
383377 }
@@ -1122,7 +1116,11 @@ xmlSwitchInputEncodingName(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
11221116 return (-1 );
11231117
11241118 res = xmlOpenCharEncodingHandler (encoding , /* output */ 0 , & handler );
1125- if (res != 0 ) {
1119+ if (res == XML_ERR_UNSUPPORTED_ENCODING ) {
1120+ xmlWarningMsg (ctxt , XML_ERR_UNSUPPORTED_ENCODING ,
1121+ "Unsupported encoding: %s\n" , BAD_CAST encoding , NULL );
1122+ return (-1 );
1123+ } else if (res != XML_ERR_OK ) {
11261124 xmlFatalErr (ctxt , res , encoding );
11271125 return (-1 );
11281126 }
@@ -1383,7 +1381,28 @@ void
13831381xmlSetDeclaredEncoding (xmlParserCtxtPtr ctxt , xmlChar * encoding ) {
13841382 if (((ctxt -> input -> flags & XML_INPUT_HAS_ENCODING ) == 0 ) &&
13851383 ((ctxt -> options & XML_PARSE_IGNORE_ENC ) == 0 )) {
1386- xmlSwitchEncodingName (ctxt , (const char * ) encoding );
1384+ xmlCharEncodingHandlerPtr handler ;
1385+ int res ;
1386+
1387+ /*
1388+ * xmlSwitchInputEncodingName treats unsupported encodings as
1389+ * warnings, but we want it to be an error in an encoding
1390+ * declaration.
1391+ */
1392+ res = xmlOpenCharEncodingHandler ((const char * ) encoding ,
1393+ /* output */ 0 , & handler );
1394+ if (res != XML_ERR_OK ) {
1395+ xmlFatalErr (ctxt , res , (const char * ) encoding );
1396+ xmlFree (encoding );
1397+ return ;
1398+ }
1399+
1400+ res = xmlSwitchInputEncoding (ctxt , ctxt -> input , handler );
1401+ if (res != XML_ERR_OK ) {
1402+ xmlFree (encoding );
1403+ return ;
1404+ }
1405+
13871406 ctxt -> input -> flags |= XML_INPUT_USES_ENC_DECL ;
13881407 } else if (ctxt -> input -> flags & XML_INPUT_AUTO_ENCODING ) {
13891408 static const char * allowedUTF8 [] = {
0 commit comments