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
void
evutil_rtrim_(char *str)
evutil_rtrim_lws_(char *str)
{
char *cp;
@ -232,7 +232,7 @@ evutil_rtrim_(char *str)
--cp;
while (*cp == ' ') {
while (*cp == ' ' || *cp == '\t') {
*cp = '\0';
if (cp == str)
break;
@ -1934,7 +1934,7 @@ evhttp_parse_headers_(struct evhttp_request *req, struct evbuffer* buffer)
goto error;
svalue += strspn(svalue, " ");
evutil_rtrim_(svalue);
evutil_rtrim_lws_(svalue);
if (evhttp_add_header(headers, skey, svalue) == -1)
goto error;

View File

@ -441,7 +441,7 @@ test_evutil_rtrim(void *ptr)
do { \
if (cp) mm_free(cp); \
cp = s ? mm_strdup(s) : NULL; \
evutil_rtrim_(cp); \
evutil_rtrim_lws_(cp); \
if (result == NULL) \
tt_ptr_op(cp, ==, NULL); \
else \
@ -461,6 +461,14 @@ test_evutil_rtrim(void *ptr)
TEST_TRIM("a ", "a");
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:
if (cp)
mm_free(cp);

View File

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