diff --git a/http.c b/http.c index 96c5305d..42a44f71 100644 --- a/http.c +++ b/http.c @@ -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; diff --git a/test/regress_util.c b/test/regress_util.c index 2f20e942..6c8374d0 100644 --- a/test/regress_util.c +++ b/test/regress_util.c @@ -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); diff --git a/util-internal.h b/util-internal.h index dff3d70b..fa29f271 100644 --- a/util-internal.h +++ b/util-internal.h @@ -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