Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
5078760d
Commit
5078760d
authored
Feb 17, 2018
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mime types are now case-insensitive, which fixes #179
parent
e40dd43e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
12 deletions
+29
-12
src/common/mime.cc
src/common/mime.cc
+12
-12
tests/mime_test.cc
tests/mime_test.cc
+17
-0
No files found.
src/common/mime.cc
View file @
5078760d
...
...
@@ -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
...
...
tests/mime_test.cc
View file @
5078760d
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment