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) { ...@@ -119,10 +119,10 @@ MediaType::parseRaw(const char* str, size_t len) {
// //
// Watch out, this pattern is repeated throughout the function // Watch out, this pattern is repeated throughout the function
do { do {
#define TYPE(val, s) \ #define TYPE(val, s) \
if (match_raw(s, sizeof s - 1, cursor)) { \ if (match_string(s, sizeof s - 1, cursor, CaseSensitivity::Insensitive)) { \
top = Type::val; \ top = Type::val; \
break; \ break; \
} }
MIME_TYPES MIME_TYPES
#undef TYPE #undef TYPE
...@@ -146,10 +146,10 @@ MediaType::parseRaw(const char* str, size_t len) { ...@@ -146,10 +146,10 @@ MediaType::parseRaw(const char* str, size_t len) {
sub = Subtype::Vendor; sub = Subtype::Vendor;
} else { } else {
do { do {
#define SUB_TYPE(val, s) \ #define SUB_TYPE(val, s) \
if (match_raw(s, sizeof s - 1, cursor)) { \ if (match_string(s, sizeof s - 1, cursor, CaseSensitivity::Insensitive)) { \
sub = Subtype::val; \ sub = Subtype::val; \
break; \ break; \
} }
MIME_SUBTYPES MIME_SUBTYPES
#undef SUB_TYPE #undef SUB_TYPE
...@@ -176,10 +176,10 @@ MediaType::parseRaw(const char* str, size_t len) { ...@@ -176,10 +176,10 @@ MediaType::parseRaw(const char* str, size_t len) {
StreamCursor::Token suffixToken(cursor); StreamCursor::Token suffixToken(cursor);
do { do {
#define SUFFIX(val, s, _) \ #define SUFFIX(val, s, _) \
if (match_raw(s, sizeof s - 1, cursor)) { \ if (match_string(s, sizeof s - 1, cursor, CaseSensitivity::Insensitive)) { \
suffix = Suffix::val; \ suffix = Suffix::val; \
break; \ break; \
} }
MIME_SUFFIXES MIME_SUFFIXES
#undef SUFFIX #undef SUFFIX
......
...@@ -137,3 +137,20 @@ TEST(mime_test, invalid_parsing) { ...@@ -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="), HttpError);
ASSERT_THROW(MediaType::fromString("text/html; q=0.21; charset=ISO-8859-4; "), 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