diff --git a/lib/http.c b/lib/http.c index 73920cd748..6ccc273d13 100644 --- a/lib/http.c +++ b/lib/http.c @@ -214,6 +214,8 @@ static CURLcode copy_custom_value(const char *header, char **valp) * * This function MUST be used after the header has already been confirmed to * lead with "word:". + * + * @unittest: 1626 */ char *Curl_copy_header_value(const char *header) { diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 41565b91cc..97d4b2f22d 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -214,7 +214,7 @@ test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 \ test1598 test1599 test1600 test1601 test1602 test1603 test1604 test1605 \ test1606 test1607 test1608 test1609 test1610 test1611 test1612 test1613 \ test1614 test1615 test1616 test1617 \ -test1620 test1621 test1622 test1623 test1624 test1625 \ +test1620 test1621 test1622 test1623 test1624 test1625 test1626 \ \ test1630 test1631 test1632 test1633 test1634 test1635 test1636 test1637 \ \ diff --git a/tests/data/test1626 b/tests/data/test1626 new file mode 100644 index 0000000000..e56236dbd4 --- /dev/null +++ b/tests/data/test1626 @@ -0,0 +1,25 @@ + + + + +unittest +Curl_copy_header_value + + + + + +unittest +http + + +Curl_copy_header_value unit test + + + + + +28 invokes + + + diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc index c9996276c8..a302e839ed 100644 --- a/tests/unit/Makefile.inc +++ b/tests/unit/Makefile.inc @@ -37,7 +37,7 @@ TESTS_C = \ unit1600.c unit1601.c unit1602.c unit1603.c unit1605.c unit1606.c \ unit1607.c unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c \ unit1615.c unit1616.c unit1620.c \ - unit1625.c \ + unit1625.c unit1626.c \ unit1636.c \ unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c \ unit1657.c unit1658.c unit1660.c unit1661.c unit1663.c unit1664.c \ diff --git a/tests/unit/unit1626.c b/tests/unit/unit1626.c new file mode 100644 index 0000000000..80bb4d1181 --- /dev/null +++ b/tests/unit/unit1626.c @@ -0,0 +1,130 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ +#include "unitcheck.h" + +#ifndef CURL_DISABLE_HTTP + +#include "urldata.h" +#include "url.h" + +struct check1626 { + const char *in; /* send this in */ + const char *out; /* expect this out */ +}; + +static CURLcode test_unit1626(const char *arg) +{ + size_t i; + static const struct check1626 list[] = { + /* basic */ + { "Header: value", "value" }, + /* no space */ + { "Header:value", "value" }, + /* multiple spaces */ + { "Header: value", "value" }, + /* tabs */ + { "Header: \tvalue", "value" }, + /* trailing space */ + { "Header: value ", "value" }, + /* leading and trailing spaces */ + { "Header: value ", "value" }, + /* nothing after colon */ + { "Header:", "" }, + /* spaces-only after colon */ + { "Header: ", "" }, + /* spaces and tabs after colon */ + { "Header: \t ", "" }, + /* spaces in the value */ + { "Header: one two", "one two" }, + /* multiple spaces in the value */ + { "Header: one two a b c ", "one two a b c" }, + /* realistic */ + { "Header: text/html", "text/html" }, + /* ending with CR */ + { "Header: value\r", "value" }, + /* ending with LF */ + { "Header: value\n", "value" }, + /* quoted value */ + { "Header: \"value\"\n", "\"value\"" }, + /* quoted value with trailing space */ + { "Header: \"value\" ", "\"value\"" }, + /* leading whitespace before header name */ + { " Header: value", "value" }, + /* tab before colon */ + { "Header\t: value", "value" }, + /* mixed whitespace after colon */ + { "Header:\t value", "value" }, + /* value containing colon */ + { "Header: foo:bar", "foo:bar" }, + /* multiple colons */ + { "Header: foo:bar:baz", "foo:bar:baz" }, + /* tab-only value */ + { "Header:\t\t", "" }, + /* CRLF ending */ + { "Header: value\r\n", "value" }, + /* value with internal tabs */ + { "Header: foo\tbar", "foo\tbar" }, + /* value with leading tab trimmed */ + { "Header:\tfoo", "foo" }, + /* colon with spaces before it */ + { "Header : value", "value" }, + /* multiple spaces before colon */ + { "Header : value", "value" }, + /* spaces around colon */ + { "Header : value", "value" }, + }; + + (void)arg; + + for(i = 0; i < CURL_ARRAYSIZE(list); i++) { + bool ok; + char *get = Curl_copy_header_value(list[i].in); + + ok = get && !strcmp(list[i].out, get); + if(!ok) { + curl_mprintf("Input: %s\n" + "Got: %s\n" + "Expected: %s\n", + list[i].in, get, list[i].out); + } + curlx_free(get); + if(!ok) + break; + } + + curl_mprintf("%zu invokes\n", i); + + if(i != CURL_ARRAYSIZE(list)) + return CURLE_FAILED_INIT; + + return CURLE_OK; +} +#else +/* for HTTP-disabled builds */ +static CURLcode test_unit1626(const char *arg) +{ + (void)arg; + return CURLE_OK; +} +#endif