Skip to content

Commit

Permalink
accept multiple whitespaces between tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
i110 committed May 16, 2019
1 parent 1d2b8a1 commit a6ab773
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions picohttpparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ static const char *parse_request(const char *buf, const char *buf_end, const cha

/* parse request line */
ADVANCE_TOKEN(*method, *method_len);
++buf;
while (*buf == ' ') ++buf;
ADVANCE_TOKEN(*path, *path_len);
++buf;
while (*buf == ' ') ++buf;
if (*method_len == 0 || *path_len == 0) {
*ret = -1;
return NULL;
Expand Down Expand Up @@ -422,6 +422,7 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min
*ret = -1;
return NULL;
}
while (*buf == ' ') ++buf;
/* parse status code, we want at least [:digit:][:digit:][:digit:]<other char> to try to parse */
if (buf_end - buf < 4) {
*ret = -2;
Expand All @@ -437,8 +438,10 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min
/* ok */
} else if (**msg == ' ') {
/* remove preceding space */
++*msg;
--*msg_len;
while (**msg == ' ') {
++*msg;
--*msg_len;
}
} else {
/* garbage found after status code */
*ret = -1;
Expand Down
4 changes: 4 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ static void test_request(void)
PARSE("GET / HTTP/1.0\r\nfoo: a \t \r\n\r\n", 0, 0, "exclude leading and trailing spaces in header value");
ok(bufis(headers[0].value, headers[0].value_len, "a"));

PARSE("GET / HTTP/1.0\r\n\r\n", 0, 0, "accept multiple spaces between tokens");

#undef PARSE
}

Expand Down Expand Up @@ -245,6 +247,8 @@ static void test_response(void)
PARSE("HTTP/1.1 200 OK\r\nbar: \t b\t \t\r\n\r\n", 0, 0, "exclude leading and trailing spaces in header value");
ok(bufis(headers[0].value, headers[0].value_len, "b"));

PARSE("HTTP/1.1 200 OK\r\n\r\n", 0, 0, "accept multiple spaces between tokens");

#undef PARSE
}

Expand Down

0 comments on commit a6ab773

Please sign in to comment.