1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

Fix HTML serialization with UTF-8 encoding

If the encoding is specified as UTF-8, make sure to use a NULL encoding
handler.
This commit is contained in:
Nick Wellnhofer
2018-10-13 16:12:14 +02:00
parent ee501f5449
commit d459831c1b

View File

@@ -502,16 +502,16 @@ htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc,
if (handler == NULL) if (handler == NULL)
htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding); htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding);
} }
} else {
/*
* Fallback to HTML or ASCII when the encoding is unspecified
*/
if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii");
} }
/*
* Fallback to HTML or ASCII when the encoding is unspecified
*/
if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii");
/* /*
* save the content to a temp buffer. * save the content to a temp buffer.
*/ */
@@ -575,19 +575,17 @@ htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) {
if (handler == NULL) if (handler == NULL)
htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding); htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding);
} else {
handler = xmlFindCharEncodingHandler(encoding);
} }
} else {
/*
* Fallback to HTML or ASCII when the encoding is unspecified
*/
if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii");
} }
/*
* Fallback to HTML or ASCII when the encoding is unspecified
*/
if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii");
buf = xmlAllocOutputBufferInternal(handler); buf = xmlAllocOutputBufferInternal(handler);
if (buf == NULL) { if (buf == NULL) {
*mem = NULL; *mem = NULL;
@@ -1096,19 +1094,17 @@ htmlDocDump(FILE *f, xmlDocPtr cur) {
handler = xmlFindCharEncodingHandler(encoding); handler = xmlFindCharEncodingHandler(encoding);
if (handler == NULL) if (handler == NULL)
htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding); htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding);
} else {
handler = xmlFindCharEncodingHandler(encoding);
} }
} else {
/*
* Fallback to HTML or ASCII when the encoding is unspecified
*/
if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii");
} }
/*
* Fallback to HTML or ASCII when the encoding is unspecified
*/
if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii");
buf = xmlOutputBufferCreateFile(f, handler); buf = xmlOutputBufferCreateFile(f, handler);
if (buf == NULL) return(-1); if (buf == NULL) return(-1);
htmlDocContentDumpOutput(buf, cur, NULL); htmlDocContentDumpOutput(buf, cur, NULL);
@@ -1149,16 +1145,16 @@ htmlSaveFile(const char *filename, xmlDocPtr cur) {
if (handler == NULL) if (handler == NULL)
htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding); htmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding);
} }
} else {
/*
* Fallback to HTML or ASCII when the encoding is unspecified
*/
if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii");
} }
/*
* Fallback to HTML or ASCII when the encoding is unspecified
*/
if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii");
/* /*
* save the content to a temp buffer. * save the content to a temp buffer.
*/ */
@@ -1206,15 +1202,15 @@ htmlSaveFileFormat(const char *filename, xmlDocPtr cur,
htmlSetMetaEncoding(cur, (const xmlChar *) encoding); htmlSetMetaEncoding(cur, (const xmlChar *) encoding);
} else { } else {
htmlSetMetaEncoding(cur, (const xmlChar *) "UTF-8"); htmlSetMetaEncoding(cur, (const xmlChar *) "UTF-8");
}
/* /*
* Fallback to HTML or ASCII when the encoding is unspecified * Fallback to HTML or ASCII when the encoding is unspecified
*/ */
if (handler == NULL) if (handler == NULL)
handler = xmlFindCharEncodingHandler("HTML"); handler = xmlFindCharEncodingHandler("HTML");
if (handler == NULL) if (handler == NULL)
handler = xmlFindCharEncodingHandler("ascii"); handler = xmlFindCharEncodingHandler("ascii");
}
/* /*
* save the content to a temp buffer. * save the content to a temp buffer.