[libsoup/pgriffis/content-disposition] headers: Support invalid content-disposition with only directives
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/pgriffis/content-disposition] headers: Support invalid content-disposition with only directives
- Date: Wed, 14 Jul 2021 16:41:29 +0000 (UTC)
commit b546ac773ecc76dbd710bb98726cdae469e6a1fc
Author: Patrick Griffis <pgriffis igalia com>
Date: Wed Jul 14 11:41:19 2021 -0500
headers: Support invalid content-disposition with only directives
libsoup/soup-message-headers.c | 38 +++++++++++++++++++++++---------------
tests/header-parsing-test.c | 16 ++++++++++++++++
2 files changed, 39 insertions(+), 15 deletions(-)
---
diff --git a/libsoup/soup-message-headers.c b/libsoup/soup-message-headers.c
index 88c7e29a..9e4ae136 100644
--- a/libsoup/soup-message-headers.c
+++ b/libsoup/soup-message-headers.c
@@ -1447,21 +1447,29 @@ parse_content_foo (SoupMessageHeaders *hdrs,
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 directives,
+ * we can be flexible about handling these */
+ if (g_str_has_prefix (header, "filename") || g_str_has_prefix (header, "name")) {
+ 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 {
+ semi = strchr (header, ';');
+ if (semi)
+ semi++;
+ }
+ }
if (!params)
return TRUE;
diff --git a/tests/header-parsing-test.c b/tests/header-parsing-test.c
index 0e5f252a..8e4570b2 100644
--- a/tests/header-parsing-test.c
+++ b/tests/header-parsing-test.c
@@ -1032,6 +1032,7 @@ 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_INVALID "filename=\"test.txt\""
static void
do_content_disposition_tests (void)
@@ -1100,6 +1101,21 @@ 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_INVALID);
+ if (!soup_message_headers_get_content_disposition (hdrs,
+ &disposition,
+ ¶ms)) {
+ 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);
+
soup_message_headers_unref (hdrs);
/* Ensure that soup-multipart always quotes filename */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]