Commit d9f97292 authored by Patrick Griffis's avatar Patrick Griffis 💬 Committed by Patrick Griffis
Browse files

headers: Support content-disposition missing disposition-type

parent d4171ba3
Pipeline #297514 passed with stages
in 3 minutes and 10 seconds
......@@ -1442,26 +1442,36 @@ parse_content_foo (SoupMessageHeaders *hdrs,
{
const char *header;
char *semi;
char *equal;
header = soup_message_headers_get_one_common (hdrs, header_name);
if (!header)
return FALSE;
if (foo) {
*foo = g_strdup (header);
semi = strchr (*foo, ';');
if (semi) {
char *p = semi;
*semi++ = '\0';
while (p - 1 > *foo && g_ascii_isspace(p[-1]))
*(--p) = '\0';
}
} else {
semi = strchr (header, ';');
if (semi)
semi++;
}
/* Some websites send an invalid disposition that only contains parameters;
* We can be flexible about handling these by detecting if the first word
* is a parameter (foo=bar). */
equal = strchr (header, '=');
semi = strchr (header, ';');
if (equal && (!semi || (equal < semi))) {
semi = (char *)header;
if (foo)
*foo = NULL;
} else if (foo) {
*foo = g_strdup (header);
semi = strchr (*foo, ';');
if (semi) {
char *p = semi;
*semi++ = '\0';
while (p - 1 > *foo && g_ascii_isspace(p[-1]))
*(--p) = '\0';
}
} else {
/* Skip type, we don't store it */
if (semi)
semi++;
}
if (!params)
return TRUE;
......
......@@ -1032,13 +1032,15 @@ do_param_list_tests (void)
#define RFC5987_TEST_HEADER_UTF8 "attachment; filename*=UTF-8''t%C3%A9st.txt; filename=\"test.txt\""
#define RFC5987_TEST_HEADER_ISO "attachment; filename=\"test.txt\"; filename*=iso-8859-1''t%E9st.txt"
#define RFC5987_TEST_HEADER_FALLBACK "attachment; filename*=Unknown''t%FF%FF%FFst.txt; filename=\"test.txt\""
#define RFC5987_TEST_HEADER_NO_TYPE "filename=\"test.txt\""
#define RFC5987_TEST_HEADER_NO_TYPE_2 "filename=\"test.txt\"; foo=bar"
static void
do_content_disposition_tests (void)
{
SoupMessageHeaders *hdrs;
GHashTable *params;
const char *header, *filename;
const char *header, *filename, *parameter2;
char *disposition;
GBytes *buffer;
SoupMultipart *multipart;
......@@ -1100,6 +1102,38 @@ do_content_disposition_tests (void)
g_assert_cmpstr (filename, ==, RFC5987_TEST_FALLBACK_FILENAME);
g_hash_table_destroy (params);
/* Invalid disposition with only a filename still works */
soup_message_headers_clear (hdrs);
soup_message_headers_append (hdrs, "Content-Disposition",
RFC5987_TEST_HEADER_NO_TYPE);
if (!soup_message_headers_get_content_disposition (hdrs,
&disposition,
&params)) {
soup_test_assert (FALSE, "filename-only decoding FAILED");
return;
}
g_assert_null (disposition);
filename = g_hash_table_lookup (params, "filename");
g_assert_cmpstr (filename, ==, RFC5987_TEST_FALLBACK_FILENAME);
g_hash_table_destroy (params);
/* Invalid disposition with only two parameters still works */
soup_message_headers_clear (hdrs);
soup_message_headers_append (hdrs, "Content-Disposition",
RFC5987_TEST_HEADER_NO_TYPE_2);
if (!soup_message_headers_get_content_disposition (hdrs,
&disposition,
&params)) {
soup_test_assert (FALSE, "only two parameters decoding FAILED");
return;
}
g_assert_null (disposition);
filename = g_hash_table_lookup (params, "filename");
g_assert_cmpstr (filename, ==, RFC5987_TEST_FALLBACK_FILENAME);
parameter2 = g_hash_table_lookup (params, "foo");
g_assert_cmpstr (parameter2, ==, "bar");
g_hash_table_destroy (params);
soup_message_headers_unref (hdrs);
/* Ensure that soup-multipart always quotes filename */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment