diff --git a/HTMLtree.c b/HTMLtree.c index f23ae023..5d0893b8 100644 --- a/HTMLtree.c +++ b/HTMLtree.c @@ -151,7 +151,7 @@ found_content: * htmlSetMetaEncoding: * @doc: the document * @encoding: the encoding string - * + * * Sets the current encoding in the Meta tags * NOTE: this will not change the document content encoding, just * the META flag associated. @@ -164,6 +164,7 @@ htmlSetMetaEncoding(htmlDocPtr doc, const xmlChar *encoding) { const xmlChar *content = NULL; char newcontent[100]; + newcontent[0] = 0; if (doc == NULL) return(-1); @@ -244,7 +245,7 @@ found_meta: http = 1; else { - if ((value != NULL) && + if ((value != NULL) && (!xmlStrcasecmp(attr->name, BAD_CAST"content"))) content = value; } @@ -278,8 +279,13 @@ create: xmlNewProp(meta, BAD_CAST"content", BAD_CAST newcontent); } } 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 */ - if (xmlStrcasestr(content, encoding) == NULL) { + else if (xmlStrcasestr(content, encoding) == NULL) { xmlSetProp(meta, BAD_CAST"content", BAD_CAST newcontent); } } diff --git a/python/tests/serialize.py b/python/tests/serialize.py index 5b969a9e..91753e7f 100755 --- a/python/tests/serialize.py +++ b/python/tests/serialize.py @@ -96,7 +96,7 @@ str = doc.serialize("iso-8859-1", 1) if str != """
- +hello
@@ -131,7 +131,7 @@ if str != """ str = root.serialize("iso-8859-1", 1) if str != """ - +hello
diff --git a/tree.c b/tree.c index a2fdcbf5..71fbd1d9 100644 --- a/tree.c +++ b/tree.c @@ -3732,8 +3732,8 @@ xmlFreeNode(xmlNodePtr cur) { * @cur: the node * * 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 - * unlink. + * If one need to free the node, use xmlFreeNode() routine after the + * unlink to discard it. */ void xmlUnlinkNode(xmlNodePtr cur) {