mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
Fix html serialization error and htmlSetMetaEncoding()
For https://bugzilla.gnome.org/show_bug.cgi?id=630682 The python tests were reporting errors, some of it was due to a small change in case encoding, but the main one was about htmlSetMetaEncoding(doc, NULL) being broken by not removing the associated meta tag anymore
This commit is contained in:
12
HTMLtree.c
12
HTMLtree.c
@@ -151,7 +151,7 @@ found_content:
|
|||||||
* htmlSetMetaEncoding:
|
* htmlSetMetaEncoding:
|
||||||
* @doc: the document
|
* @doc: the document
|
||||||
* @encoding: the encoding string
|
* @encoding: the encoding string
|
||||||
*
|
*
|
||||||
* Sets the current encoding in the Meta tags
|
* Sets the current encoding in the Meta tags
|
||||||
* NOTE: this will not change the document content encoding, just
|
* NOTE: this will not change the document content encoding, just
|
||||||
* the META flag associated.
|
* the META flag associated.
|
||||||
@@ -164,6 +164,7 @@ htmlSetMetaEncoding(htmlDocPtr doc, const xmlChar *encoding) {
|
|||||||
const xmlChar *content = NULL;
|
const xmlChar *content = NULL;
|
||||||
char newcontent[100];
|
char newcontent[100];
|
||||||
|
|
||||||
|
newcontent[0] = 0;
|
||||||
|
|
||||||
if (doc == NULL)
|
if (doc == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
@@ -244,7 +245,7 @@ found_meta:
|
|||||||
http = 1;
|
http = 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((value != NULL) &&
|
if ((value != NULL) &&
|
||||||
(!xmlStrcasecmp(attr->name, BAD_CAST"content")))
|
(!xmlStrcasecmp(attr->name, BAD_CAST"content")))
|
||||||
content = value;
|
content = value;
|
||||||
}
|
}
|
||||||
@@ -278,8 +279,13 @@ create:
|
|||||||
xmlNewProp(meta, BAD_CAST"content", BAD_CAST newcontent);
|
xmlNewProp(meta, BAD_CAST"content", BAD_CAST newcontent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
/* remove the meta tag if NULL is passed */
|
||||||
|
if (encoding == NULL) {
|
||||||
|
xmlUnlinkNode(meta);
|
||||||
|
xmlFreeNode(meta);
|
||||||
|
}
|
||||||
/* change the document only if there is a real encoding change */
|
/* change the document only if there is a real encoding change */
|
||||||
if (xmlStrcasestr(content, encoding) == NULL) {
|
else if (xmlStrcasestr(content, encoding) == NULL) {
|
||||||
xmlSetProp(meta, BAD_CAST"content", BAD_CAST newcontent);
|
xmlSetProp(meta, BAD_CAST"content", BAD_CAST newcontent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ str = doc.serialize("iso-8859-1", 1)
|
|||||||
if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
<title>Hello</title>
|
<title>Hello</title>
|
||||||
</head>
|
</head>
|
||||||
<body><p>hello</p></body>
|
<body><p>hello</p></body>
|
||||||
@@ -131,7 +131,7 @@ if str != """<html>
|
|||||||
str = root.serialize("iso-8859-1", 1)
|
str = root.serialize("iso-8859-1", 1)
|
||||||
if str != """<html>
|
if str != """<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
<title>Hello</title>
|
<title>Hello</title>
|
||||||
</head>
|
</head>
|
||||||
<body><p>hello</p></body>
|
<body><p>hello</p></body>
|
||||||
|
|||||||
4
tree.c
4
tree.c
@@ -3732,8 +3732,8 @@ xmlFreeNode(xmlNodePtr cur) {
|
|||||||
* @cur: the node
|
* @cur: the node
|
||||||
*
|
*
|
||||||
* Unlink a node from it's current context, the node is not freed
|
* Unlink a node from it's current context, the node is not freed
|
||||||
* If one need to free the node, use xmlNodeFree() routine after the
|
* If one need to free the node, use xmlFreeNode() routine after the
|
||||||
* unlink.
|
* unlink to discard it.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
xmlUnlinkNode(xmlNodePtr cur) {
|
xmlUnlinkNode(xmlNodePtr cur) {
|
||||||
|
|||||||
Reference in New Issue
Block a user