Commit 5078760d authored by octal's avatar octal

Mime types are now case-insensitive, which fixes #179

parent e40dd43e
......@@ -119,10 +119,10 @@ MediaType::parseRaw(const char* str, size_t len) {
//
// Watch out, this pattern is repeated throughout the function
do {
#define TYPE(val, s) \
if (match_raw(s, sizeof s - 1, cursor)) { \
top = Type::val; \
break; \
#define TYPE(val, s) \
if (match_string(s, sizeof s - 1, cursor, CaseSensitivity::Insensitive)) { \
top = Type::val; \
break; \
}
MIME_TYPES
#undef TYPE
......@@ -146,10 +146,10 @@ MediaType::parseRaw(const char* str, size_t len) {
sub = Subtype::Vendor;
} else {
do {
#define SUB_TYPE(val, s) \
if (match_raw(s, sizeof s - 1, cursor)) { \
sub = Subtype::val; \
break; \
#define SUB_TYPE(val, s) \
if (match_string(s, sizeof s - 1, cursor, CaseSensitivity::Insensitive)) { \
sub = Subtype::val; \
break; \
}
MIME_SUBTYPES
#undef SUB_TYPE
......@@ -176,10 +176,10 @@ MediaType::parseRaw(const char* str, size_t len) {
StreamCursor::Token suffixToken(cursor);
do {
#define SUFFIX(val, s, _) \
if (match_raw(s, sizeof s - 1, cursor)) { \
suffix = Suffix::val; \
break; \
#define SUFFIX(val, s, _) \
if (match_string(s, sizeof s - 1, cursor, CaseSensitivity::Insensitive)) { \
suffix = Suffix::val; \
break; \
}
MIME_SUFFIXES
#undef SUFFIX
......
......@@ -137,3 +137,20 @@ TEST(mime_test, invalid_parsing) {
ASSERT_THROW(MediaType::fromString("text/html; q=0.21; charset="), HttpError);
ASSERT_THROW(MediaType::fromString("text/html; q=0.21; charset=ISO-8859-4; "), HttpError);
}
TEST(mime_test, should_parse_case_insensitive_issue_179)
{
parse("Application/Json", [](const Mime::MediaType& mime) {
ASSERT_EQ(mime, MIME(Application, Json));
ASSERT_TRUE(mime.q().isEmpty());
});
parse("aPpliCAtion/Xhtml+XML", [](const MediaType &mime) {
ASSERT_EQ(mime, MediaType(Type::Application, Subtype::Xhtml, Suffix::Xml));
ASSERT_TRUE(mime.q().isEmpty());
});
parse("Application/Xhtml+XML; q=0.78", [](const MediaType& mime) {
ASSERT_EQ(mime.q().getOrElse(Q(0)), Q(78));
});
}
\ No newline at end of file
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