Remove trailing tabs in HTTP headers as well.

This commit is contained in:
Nick Mathewson 2012-11-16 11:29:34 -05:00
parent aa59d805f5
commit ac42519769
3 changed files with 15 additions and 6 deletions

6
http.c
View File

@ -220,7 +220,7 @@ strsep(char **s, const char *del)
#endif #endif
void void
evutil_rtrim_(char *str) evutil_rtrim_lws_(char *str)
{ {
char *cp; char *cp;
@ -232,7 +232,7 @@ evutil_rtrim_(char *str)
--cp; --cp;
while (*cp == ' ') { while (*cp == ' ' || *cp == '\t') {
*cp = '\0'; *cp = '\0';
if (cp == str) if (cp == str)
break; break;
@ -1934,7 +1934,7 @@ evhttp_parse_headers_(struct evhttp_request *req, struct evbuffer* buffer)
goto error; goto error;
svalue += strspn(svalue, " "); svalue += strspn(svalue, " ");
evutil_rtrim_(svalue); evutil_rtrim_lws_(svalue);
if (evhttp_add_header(headers, skey, svalue) == -1) if (evhttp_add_header(headers, skey, svalue) == -1)
goto error; goto error;

View File

@ -441,7 +441,7 @@ test_evutil_rtrim(void *ptr)
do { \ do { \
if (cp) mm_free(cp); \ if (cp) mm_free(cp); \
cp = s ? mm_strdup(s) : NULL; \ cp = s ? mm_strdup(s) : NULL; \
evutil_rtrim_(cp); \ evutil_rtrim_lws_(cp); \
if (result == NULL) \ if (result == NULL) \
tt_ptr_op(cp, ==, NULL); \ tt_ptr_op(cp, ==, NULL); \
else \ else \
@ -461,6 +461,14 @@ test_evutil_rtrim(void *ptr)
TEST_TRIM("a ", "a"); TEST_TRIM("a ", "a");
TEST_TRIM("abcdef gH ", "abcdef gH"); TEST_TRIM("abcdef gH ", "abcdef gH");
TEST_TRIM("\t\t", "");
TEST_TRIM(" \t", "");
TEST_TRIM("\t", "");
TEST_TRIM("a \t", "a");
TEST_TRIM("a\t ", "a");
TEST_TRIM("a\t", "a");
TEST_TRIM("abcdef gH \t ", "abcdef gH");
end: end:
if (cp) if (cp)
mm_free(cp); mm_free(cp);

View File

@ -218,8 +218,9 @@ int EVUTIL_ISUPPER_(char c);
char EVUTIL_TOUPPER_(char c); char EVUTIL_TOUPPER_(char c);
char EVUTIL_TOLOWER_(char c); char EVUTIL_TOLOWER_(char c);
/** Remove all trailing whitespace from the end of a string */ /** Remove all trailing horizontal whitespace (space or tab) from the end of a
void evutil_rtrim_(char *); * string */
void evutil_rtrim_lws_(char *);
/** Helper macro. If we know that a given pointer points to a field in a /** Helper macro. If we know that a given pointer points to a field in a