summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2009-08-10 03:42:59 +0000
committercorvid <corvid@lavabit.com>2009-08-10 03:42:59 +0000
commita73f68c762425ee2c410ff1e1880c535a4eb844f (patch)
treeb552c4657a1d19eea785b45a8380570bbaa9c34e
parent5ae7a84af061f814e796f1c8c44df112b2fca007 (diff)
follow RFC a bit more closely for Content-Type parsing
From looking at the IANA's currently-assigned media types, allowing '+' and '.' would have been enough.
-rw-r--r--src/misc.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/misc.c b/src/misc.c
index bd963128..675e71c9 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -192,10 +192,12 @@ int a_Misc_get_content_type_from_data(void *Data, size_t Size, const char **PT)
/*
* Parse Content-Type string, e.g., "text/html; charset=utf-8".
+ * Content-Type is defined in RFC 2045 section 5.1.
*/
void a_Misc_parse_content_type(const char *str, char **major, char **minor,
char **charset)
{
+ static const char tspecials_space[] = "()<>@,;:\\\"/[]?= ";
const char *s;
bool_t is_text;
@@ -208,19 +210,24 @@ void a_Misc_parse_content_type(const char *str, char **major, char **minor,
if (!str)
return;
- for (s = str; dIsalnum(*s) || (*s == '-'); s++);
+ for (s = str; *s && !iscntrl((uchar_t)*s) && !strchr(tspecials_space, *s);
+ s++) ;
if (major)
*major = dStrndup(str, s - str);
is_text = (s - str == 4) && !dStrncasecmp(str, "text", 4);
if (*s == '/') {
- for (str = ++s; dIsalnum(*s) || (*s == '-'); s++);
+ for (str = ++s;
+ *s && !iscntrl((uchar_t)*s) && !strchr(tspecials_space, *s); s++) ;
if (minor)
*minor = dStrndup(str, s - str);
}
if (is_text && charset && *s) {
- /* charset parameter is defined for text media type (RFC 2046) */
+ /* charset parameter is defined for text media type (RFC 2046).
+ * Note that is_text will no longer suffice if dillo begins to
+ * handle xhtml someday.
+ */
const char terminators[] = " ;\t";
const char key[] = "charset";