components/libxml2/patches/22.htmlSetMetaEncoding.patch
changeset 918 35e4a56e4a26
equal deleted inserted replaced
917:c2d902bbacc9 918:35e4a56e4a26
       
     1 Last file (tree.c) of original commit was left out since it modifies
       
     2 just comment where it wouldn't apply because of change in context.
       
     3 
       
     4 From 39d027cdb74371d64f68dc488556be41e1d14546 Mon Sep 17 00:00:00 2001
       
     5 From: Daniel Veillard <[email protected]>
       
     6 Date: Fri, 11 May 2012 04:38:23 +0000
       
     7 Subject: Fix html serialization error and htmlSetMetaEncoding()
       
     8 
       
     9 For https://bugzilla.gnome.org/show_bug.cgi?id=630682
       
    10 The python tests were reporting errors, some of it was due to
       
    11 a small change in case encoding, but the main one was about
       
    12 htmlSetMetaEncoding(doc, NULL) being broken by not removing
       
    13 the associated meta tag anymore
       
    14 ---
       
    15 diff --git a/HTMLtree.c b/HTMLtree.c
       
    16 index f23ae02..5d0893b 100644
       
    17 --- a/HTMLtree.c
       
    18 +++ b/HTMLtree.c
       
    19 @@ -151,7 +151,7 @@ found_content:
       
    20   * htmlSetMetaEncoding:
       
    21   * @doc:  the document
       
    22   * @encoding:  the encoding string
       
    23 - * 
       
    24 + *
       
    25   * Sets the current encoding in the Meta tags
       
    26   * NOTE: this will not change the document content encoding, just
       
    27   * the META flag associated.
       
    28 @@ -164,6 +164,7 @@ htmlSetMetaEncoding(htmlDocPtr doc, const xmlChar *encoding) {
       
    29      const xmlChar *content = NULL;
       
    30      char newcontent[100];
       
    31  
       
    32 +    newcontent[0] = 0;
       
    33  
       
    34      if (doc == NULL)
       
    35  	return(-1);
       
    36 @@ -244,7 +245,7 @@ found_meta:
       
    37  			    http = 1;
       
    38  			else
       
    39                          {
       
    40 -                           if ((value != NULL) && 
       
    41 +                           if ((value != NULL) &&
       
    42                                 (!xmlStrcasecmp(attr->name, BAD_CAST"content")))
       
    43  			       content = value;
       
    44                          }
       
    45 @@ -278,8 +279,13 @@ create:
       
    46              xmlNewProp(meta, BAD_CAST"content", BAD_CAST newcontent);
       
    47          }
       
    48      } else {
       
    49 +        /* remove the meta tag if NULL is passed */
       
    50 +        if (encoding == NULL) {
       
    51 +            xmlUnlinkNode(meta);
       
    52 +            xmlFreeNode(meta);
       
    53 +        }
       
    54          /* change the document only if there is a real encoding change */
       
    55 -        if (xmlStrcasestr(content, encoding) == NULL) {
       
    56 +        else if (xmlStrcasestr(content, encoding) == NULL) {
       
    57              xmlSetProp(meta, BAD_CAST"content", BAD_CAST newcontent);
       
    58          }
       
    59      }
       
    60 diff --git a/python/tests/serialize.py b/python/tests/serialize.py
       
    61 index 5b969a9..91753e7 100755
       
    62 --- a/python/tests/serialize.py
       
    63 +++ b/python/tests/serialize.py
       
    64 @@ -96,7 +96,7 @@ str = doc.serialize("iso-8859-1", 1)
       
    65  if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
       
    66  <html>
       
    67  <head>
       
    68 -<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
       
    69 +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
       
    70  <title>Hello</title>
       
    71  </head>
       
    72  <body><p>hello</p></body>
       
    73 @@ -131,7 +131,7 @@ if str != """<html>
       
    74  str = root.serialize("iso-8859-1", 1)
       
    75  if str != """<html>
       
    76  <head>
       
    77 -<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
       
    78 +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
       
    79  <title>Hello</title>
       
    80  </head>
       
    81  <body><p>hello</p></body>
       
    82 --
       
    83 cgit v0.9.0.2