diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 03d9eec..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -picohttpparser.* ident diff --git a/picohttpparser.c b/picohttpparser.c index baf4d7d..1904785 100644 --- a/picohttpparser.c +++ b/picohttpparser.c @@ -39,8 +39,6 @@ #endif #include "picohttpparser.h" -/* $Id$ */ - #if __GNUC__ >= 3 #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) @@ -169,9 +167,9 @@ static const char *findchar_nonprintable_fast(const char *buf, const char *buf_e return buf; #else - static const char ALIGNED(16) ranges2[] = "\000\040\177\177"; + static const char ALIGNED(16) ranges2[16] = "\000\040\177\177"; - return findchar_fast(buf, buf_end, ranges2, sizeof(ranges2) - 1, found); + return findchar_fast(buf, buf_end, ranges2, 4, found); #endif } @@ -180,15 +178,11 @@ static const char *get_token_to_eol(const char *buf, const char *buf_end, const const char *token_start = buf; #ifdef __SSE4_2__ - static const char ranges1[] = "\0\010" - /* allow HT */ - "\012\037" - /* allow SP and up to but not including DEL */ - "\177\177" - /* allow chars w. MSB set */ - ; + static const char ALIGNED(16) ranges1[16] = "\0\010" /* allow HT */ + "\012\037" /* allow SP and up to but not including DEL */ + "\177\177"; /* allow chars w. MSB set */ int found; - buf = findchar_fast(buf, buf_end, ranges1, sizeof(ranges1) - 1, &found); + buf = findchar_fast(buf, buf_end, ranges1, 6, &found); if (found) goto FOUND_CTL; #elif defined(__ARM_64BIT_STATE) && defined(__ARM_FEATURE_UNALIGNED) && !defined(__ARM_BIG_ENDIAN) @@ -433,9 +427,13 @@ static const char *parse_request(const char *buf, const char *buf_end, const cha /* parse request line */ ADVANCE_TOKEN(*method, *method_len); - ++buf; + do { + ++buf; + } while (*buf == ' '); ADVANCE_TOKEN(*path, *path_len); - ++buf; + do { + ++buf; + } while (*buf == ' '); if (*method_len == 0 || *path_len == 0) { *ret = -1; return NULL; @@ -492,10 +490,13 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min return NULL; } /* skip space */ - if (*buf++ != ' ') { + if (*buf != ' ') { *ret = -1; return NULL; } + do { + ++buf; + } while (*buf == ' '); /* parse status code, we want at least [:digit:][:digit:][:digit:] to try to parse */ if (buf_end - buf < 4) { *ret = -2; @@ -511,8 +512,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; + do { + ++*msg; + --*msg_len; + } while (**msg == ' '); } else { /* garbage found after status code */ *ret = -1; diff --git a/picohttpparser.h b/picohttpparser.h index 67fd3ee..0849f84 100644 --- a/picohttpparser.h +++ b/picohttpparser.h @@ -33,8 +33,6 @@ #define ssize_t intptr_t #endif -/* $Id$ */ - #ifdef __cplusplus extern "C" { #endif diff --git a/test.c b/test.c index 2a93477..abcd0a9 100644 --- a/test.c +++ b/test.c @@ -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 } @@ -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 }