Commit 5078760d authored by octal's avatar octal

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

parent e40dd43e
...@@ -120,7 +120,7 @@ MediaType::parseRaw(const char* str, size_t len) { ...@@ -120,7 +120,7 @@ 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; \
} }
...@@ -147,7 +147,7 @@ MediaType::parseRaw(const char* str, size_t len) { ...@@ -147,7 +147,7 @@ MediaType::parseRaw(const char* str, size_t len) {
} 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; \
} }
...@@ -177,7 +177,7 @@ MediaType::parseRaw(const char* str, size_t len) { ...@@ -177,7 +177,7 @@ MediaType::parseRaw(const char* str, size_t len) {
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; \
} }
......
...@@ -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