From 5972678db845fe1f95214d72e0732d2a5128ef01 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 1 May 2025 00:37:57 +0200 Subject: Allow whitespaces before separator --- src/misc.h | 4 +++- test/unit/disposition.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/misc.h b/src/misc.h index 3b16566d..81c109c2 100644 --- a/src/misc.h +++ b/src/misc.h @@ -59,7 +59,9 @@ static inline void a_Misc_parse_content_disposition(const char *disposition, cha return; } - /* FIXME: what about "attachment ; filename=foo"? */ + /* Skip blanks like "attachment ; ..." */ + while (*s == ' ' || *s == '\t') + s++; /* Stop if the terminator is not ; */ if (*s != ';') diff --git a/test/unit/disposition.c b/test/unit/disposition.c index 47e2f4eb..92de9181 100644 --- a/test/unit/disposition.c +++ b/test/unit/disposition.c @@ -35,9 +35,20 @@ struct testcase cases[] = { { "attachment; filename=\"foo", "attachment", NULL }, { "attachment; filename= ", "attachment", NULL }, { "attachment; filename=\"", "attachment", NULL }, + { "attachment; filename=\"\"", "attachment", NULL }, + { "attachment; filename=\"a\"", "attachment", "a" }, { "attachment; filename=\"foo", "attachment", NULL }, { "attachment; filename=~/foo", "attachment", "__foo" }, + /* Note that due to the rules for implied linear whitespace (Section 2.1 of + * [RFC2616]), OPTIONAL whitespace can appear between words (token or + * quoted-string) and separator characters. */ + { "attachment ; filename=foo", "attachment", "foo" }, + { "attachment; filename =foo", "attachment", "foo" }, + { "attachment; filename= foo", "attachment", "foo" }, + { "attachment; filename = foo", "attachment", "foo" }, + { "attachment ; filename = foo", "attachment", "foo" }, + /* See http://test.greenbytes.de/tech/tc2231/ */ { "inline", "inline", NULL }, { "\"inline\"", NULL, NULL }, -- cgit v1.2.3