[libsoup/pgriffis/content-type-regression] headers: Fix parsing of Content-Type




commit 7bec1c4f475e7f91529463abdbc7a72417ed44bc
Author: Patrick Griffis <pgriffis igalia com>
Date:   Thu Jul 22 10:20:56 2021 -0500

    headers: Fix parsing of Content-Type
    
    With d9f97292 the intention was only to change the behavior of 
soup_message_headers_get_content_disposition()
    however parse_content_foo() is also used for Content-Type.
    
    Fixes #232

 libsoup/soup-message-headers.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/libsoup/soup-message-headers.c b/libsoup/soup-message-headers.c
index 2dfea525..b585d6ca 100644
--- a/libsoup/soup-message-headers.c
+++ b/libsoup/soup-message-headers.c
@@ -43,7 +43,8 @@
 static gboolean parse_content_foo (SoupMessageHeaders *hdrs,
                                    SoupHeaderName      header_name,
                                    char              **foo,
-                                   GHashTable        **params);
+                                   GHashTable        **params,
+                                                                  gboolean            allow_empty_type);
 typedef struct {
         SoupHeaderName name;
         char *value;
@@ -174,7 +175,7 @@ soup_message_headers_set (SoupMessageHeaders *hdrs,
                 if (value) {
                         char *content_type = NULL, *p;
 
-                        parse_content_foo (hdrs, SOUP_HEADER_CONTENT_TYPE, &content_type, NULL);
+                        parse_content_foo (hdrs, SOUP_HEADER_CONTENT_TYPE, &content_type, NULL, FALSE);
                         g_assert (content_type != NULL);
 
                         p = strpbrk (content_type, " /");
@@ -1437,8 +1438,9 @@ soup_message_headers_set_content_range (SoupMessageHeaders  *hdrs,
 static gboolean
 parse_content_foo (SoupMessageHeaders *hdrs,
                    SoupHeaderName      header_name,
-                  char              **foo,
-                   GHashTable        **params)
+                   char              **foo,
+                   GHashTable        **params,
+                   gboolean            allow_empty_type)
 {
        const char *header;
        char *semi;
@@ -1453,7 +1455,7 @@ parse_content_foo (SoupMessageHeaders *hdrs,
          * is a parameter (foo=bar). */
         equal = strchr (header, '=');
         semi = strchr (header, ';');
-        if (equal && (!semi || (equal < semi))) {
+        if (allow_empty_type && (equal && (!semi || (equal < semi)))) {
                 semi = (char *)header;
                 if (foo)
                         *foo = NULL;
@@ -1533,7 +1535,7 @@ soup_message_headers_get_content_type (SoupMessageHeaders  *hdrs,
                return NULL;
 
        if (params)
-               parse_content_foo (hdrs, SOUP_HEADER_CONTENT_TYPE, NULL, params);
+               parse_content_foo (hdrs, SOUP_HEADER_CONTENT_TYPE, NULL, params, FALSE);
        return hdrs->content_type;
 }
 
@@ -1594,7 +1596,7 @@ soup_message_headers_get_content_disposition (SoupMessageHeaders  *hdrs,
        gpointer orig_key, orig_value;
 
        if (!parse_content_foo (hdrs, SOUP_HEADER_CONTENT_DISPOSITION,
-                               disposition, params))
+                               disposition, params, TRUE))
                return FALSE;
 
        /* If there is a filename parameter, make sure it contains


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]