changeset 949:691053e40394

Fixed handling of META's content-type with no MIME type (e.g. only charset). e.g. some links at http://git.kernel.org/gitweb.cgi didn't render. e.g. #2 This page didn't render: <html> <head> <meta http-equiv="content-type" content="; charset=utf-8"/> <title></title> </head> <body> Generating.... </body> </html>
author Jorge Arellano Cid <jcid@dillo.org>
date Sun, 15 Feb 2009 16:04:56 -0300
parents f06d5c581f58
children 397174ba98a3
files ChangeLog src/cache.c src/html.cc src/nav.c
diffstat 4 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Feb 15 09:06:21 2009 -0300
+++ b/ChangeLog	Sun Feb 15 16:04:56 2009 -0300
@@ -69,6 +69,7 @@
  - Removed the nav.h dependency from html.cc
  - Made the repush() operation more general and suited for CSS use.
  - Fixed collapsing of whitespace entities in HTML mode.
+ - Fixed handling of META's content-type with no MIME type (e.g. only charset).
    Patches: Jorge Arellano Cid
 
 dw
--- a/src/cache.c	Sun Feb 15 09:06:21 2009 -0300
+++ b/src/cache.c	Sun Feb 15 16:04:56 2009 -0300
@@ -53,6 +53,7 @@
    char *TypeDet;            /* MIME type string (detected from data) */
    char *TypeHdr;            /* MIME type string as from the HTTP Header */
    char *TypeMeta;           /* MIME type string from META HTTP-EQUIV */
+   char *TypeNorm;           /* MIME type string normalized */
    Dstr *Header;             /* HTTP header */
    const DilloUrl *Location; /* New URI for redirects */
    Dlist *Auth;              /* Authentication fields */
@@ -208,6 +209,7 @@
    NewEntry->TypeDet = NULL;
    NewEntry->TypeHdr = NULL;
    NewEntry->TypeMeta = NULL;
+   NewEntry->TypeNorm = NULL;
    NewEntry->Header = dStr_new("");
    NewEntry->Location = NULL;
    NewEntry->Auth = NULL;
@@ -313,6 +315,7 @@
    dFree(entry->TypeDet);
    dFree(entry->TypeHdr);
    dFree(entry->TypeMeta);
+   dFree(entry->TypeNorm);
    dStr_free(entry->Header, TRUE);
    a_Url_free((DilloUrl *)entry->Location);
    Cache_auth_free(entry->Auth);
@@ -460,8 +463,8 @@
  */
 static const char *Cache_current_content_type(CacheEntry_t *entry)
 {
-   return entry->TypeMeta ? entry->TypeMeta : entry->TypeHdr ? entry->TypeHdr :
-          entry->TypeDet;
+   return entry->TypeNorm ? entry->TypeNorm : entry->TypeMeta ? entry->TypeMeta
+          : entry->TypeHdr ? entry->TypeHdr : entry->TypeDet;
 }
 
 /*
@@ -490,8 +493,8 @@
 const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype,
                                      const char *from)
 {
-   char *charset;
    const char *curr;
+   char *major, *minor, *charset;
    CacheEntry_t *entry = Cache_entry_search_with_redirect(url);
 
    dReturn_val_if_fail (entry != NULL, NULL);
@@ -512,7 +515,12 @@
       }
       if (a_Misc_content_type_cmp(curr, ctype)) {
          /* ctype gives one different from current */
-         a_Misc_parse_content_type(ctype, NULL, NULL, &charset);
+         a_Misc_parse_content_type(ctype, &major, &minor, &charset);
+         if (*from == 'm' && charset &&
+             ((!major || !*major) && (!minor || !*minor))) {
+            /* META only gives charset; use detected MIME type too */
+            entry->TypeNorm = dStrconcat(entry->TypeDet, ctype, NULL);
+         }
          if (charset) {
             if (entry->CharsetDecoder)
                a_Decode_free(entry->CharsetDecoder);
@@ -1111,13 +1119,13 @@
             if (TypeMismatch) {
                AbortEntry = TRUE;
             } else {
-               const char *content_type = Cache_current_content_type(entry);
-               st = a_Web_dispatch_by_type(content_type, ClientWeb,
+               const char *curr_type = Cache_current_content_type(entry);
+               st = a_Web_dispatch_by_type(curr_type, ClientWeb,
                                            &Client->Callback, &Client->CbData);
                if (st == -1) {
                   /* MIME type is not viewable */
                   if (ClientWeb->flags & WEB_RootUrl) {
-                     MSG("Content-Type '%s' not viewable.\n", content_type);
+                     MSG("Content-Type '%s' not viewable.\n", curr_type);
                      /* prepare a download offer... */
                      AbortEntry = OfferDownload = TRUE;
                   } else {
--- a/src/html.cc	Sun Feb 15 09:06:21 2009 -0300
+++ b/src/html.cc	Sun Feb 15 16:04:56 2009 -0300
@@ -2792,12 +2792,13 @@
          ds_msg = dStr_sized_new(256);
          dStr_sprintf(ds_msg, meta_template, content, delay_str);
          {
-            int SaveFlags = html->InFlags;
+            int o_InFlags = html->InFlags;
+            int o_TagSoup = html->TagSoup;
             html->InFlags = IN_BODY;
             html->TagSoup = false;
             Html_write_raw(html, ds_msg->str, ds_msg->len, 0);
-            html->TagSoup = true;
-            html->InFlags = SaveFlags;
+            html->TagSoup = o_TagSoup;
+            html->InFlags = o_InFlags;
          }
          dStr_free(ds_msg, 1);
 
--- a/src/nav.c	Sun Feb 15 09:06:21 2009 -0300
+++ b/src/nav.c	Sun Feb 15 16:04:56 2009 -0300
@@ -368,7 +368,7 @@
 
 static void Nav_repush_callback(void *data)
 {
-   _MSG(">>>   Nav_repush_callback <<<<\n");
+   _MSG(">>>> Nav_repush_callback <<<<\n");
    Nav_repush(data);
    a_Timeout_remove();
 }