]> granicus.if.org Git - libevent/commitdiff
Remove trailing tabs in HTTP headers as well.
authorNick Mathewson <nickm@torproject.org>
Fri, 16 Nov 2012 16:29:34 +0000 (11:29 -0500)
committerNick Mathewson <nickm@torproject.org>
Fri, 16 Nov 2012 16:29:34 +0000 (11:29 -0500)
http.c
test/regress_util.c
util-internal.h

diff --git a/http.c b/http.c
index 96c5305d3526ec936aeb01b68cd48373324b31ed..42a44f71f37b040a899721fdca46829be56668f4 100644 (file)
--- 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;
index 2f20e942440a9c36e8432f8ffd4ad92abcf1fa37..6c8374d0bf5aa47dd5ce8d43fae7c103f7f259c0 100644 (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);
index dff3d70b717bf915d9ba8482a740b59578826b67..fa29f271441f09089a94e9a8688cca4c0b4cc07c 100644 (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