Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions proxy/hdrs/HttpCompat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ HttpCompat::parse_tok_list(StrList *list, int trim_quotes, const char *string, i
int in_quote;
const char quot = '\"';
const char *s, *e, *l, *s_before_skipping_ws;
int index, byte_length, hit_sep;
int index, byte_length, hit_sep, trim_end_quote;

if ((string == nullptr) || (list == nullptr) || (sep == NUL)) {
return;
Expand Down Expand Up @@ -113,14 +113,16 @@ HttpCompat::parse_tok_list(StrList *list, int trim_quotes, const char *string, i
#define is_unquoted_separator(c) ((c == sep) && !in_quote)

if (*s == quot) {
in_quote = 1;
e = s + 1; // start after quote
in_quote = 1;
e = s + 1; // start after quote
trim_end_quote = trim_quotes;
if (trim_quotes) {
++s; // trim starting quote
}
} else {
in_quote = 0;
e = s;
in_quote = 0;
trim_end_quote = 0;
e = s;
}

while ((e <= l) && !is_unquoted_separator(*e)) {
Expand All @@ -142,7 +144,7 @@ HttpCompat::parse_tok_list(StrList *list, int trim_quotes, const char *string, i
while ((e > s) && ParseRules::is_ws(*(e - 1))) {
--e; // eat trailing ws
}
if ((e > s) && (*(e - 1) == quot) && trim_quotes) {
if ((e > s) && (*(e - 1) == quot) && trim_end_quote) {
--e; // eat trailing quote
}

Expand Down
188 changes: 93 additions & 95 deletions proxy/hdrs/unit_tests/test_Hdrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1822,28 +1822,25 @@ TEST_CASE("HdrTest", "[proxy][hdrtest]")
int len;
} pieces[4];
} tests[] = {
{",", 2, {{0, 0}, {1, 0}, {-1, 0}, {-1, 0}}},
{"", 1, {{0, 0}, {-1, 0}, {-1, 0}, {-1, 0}}},
{" ", 1, {{0, 0}, {-1, 0}, {-1, 0}, {-1, 0}}},
{", ", 2, {{0, 0}, {1, 0}, {-1, 0}, {-1, 0}}},
{",,", 3, {{0, 0}, {1, 0}, {2, 0}, {-1, 0}}},
{" ,", 2, {{0, 0}, {2, 0}, {-1, 0}, {-1, 0}}},
{" , ", 2, {{0, 0}, {2, 0}, {-1, 0}, {-1, 0}}},
{"a, ", 2, {{0, 1}, {2, 0}, {-1, 0}, {-1, 0}}},
{" a, ", 2, {{1, 1}, {3, 0}, {-1, 0}, {-1, 0}}},
{" ,a", 2, {{0, 0}, {2, 1}, {-1, 0}, {-1, 0}}},
{" , a", 2, {{0, 0}, {3, 1}, {-1, 0}, {-1, 0}}},
{"a,a", 2, {{0, 1}, {2, 1}, {-1, 0}, {-1, 0}}},
{"foo", 1, {{0, 3}, {-1, 0}, {-1, 0}, {-1, 0}}},
{"foo,", 2, {{0, 3}, {4, 0}, {-1, 0}, {-1, 0}}},
{"foo, ", 2, {{0, 3}, {4, 0}, {-1, 0}, {-1, 0}}},
{"foo, bar", 2, {{0, 3}, {5, 3}, {-1, 0}, {-1, 0}}},
{"foo, bar,", 3, {{0, 3}, {5, 3}, {9, 0}, {-1, 0}}},
{"foo, bar, ", 3, {{0, 3}, {5, 3}, {9, 0}, {-1, 0}}},
{
",foo,bar,", 4,
{{0, 0}, {1, 3}, {5, 3}, {9, 0}},
},
{",", 2, {{0, 0}, {1, 0}, {-1, 0}, {-1, 0}} },
{"", 1, {{0, 0}, {-1, 0}, {-1, 0}, {-1, 0}}},
{" ", 1, {{0, 0}, {-1, 0}, {-1, 0}, {-1, 0}}},
{", ", 2, {{0, 0}, {1, 0}, {-1, 0}, {-1, 0}} },
{",,", 3, {{0, 0}, {1, 0}, {2, 0}, {-1, 0}} },
{" ,", 2, {{0, 0}, {2, 0}, {-1, 0}, {-1, 0}} },
{" , ", 2, {{0, 0}, {2, 0}, {-1, 0}, {-1, 0}} },
{"a, ", 2, {{0, 1}, {2, 0}, {-1, 0}, {-1, 0}} },
{" a, ", 2, {{1, 1}, {3, 0}, {-1, 0}, {-1, 0}} },
{" ,a", 2, {{0, 0}, {2, 1}, {-1, 0}, {-1, 0}} },
{" , a", 2, {{0, 0}, {3, 1}, {-1, 0}, {-1, 0}} },
{"a,a", 2, {{0, 1}, {2, 1}, {-1, 0}, {-1, 0}} },
{"foo", 1, {{0, 3}, {-1, 0}, {-1, 0}, {-1, 0}}},
{"foo,", 2, {{0, 3}, {4, 0}, {-1, 0}, {-1, 0}} },
{"foo, ", 2, {{0, 3}, {4, 0}, {-1, 0}, {-1, 0}} },
{"foo, bar", 2, {{0, 3}, {5, 3}, {-1, 0}, {-1, 0}} },
{"foo, bar,", 3, {{0, 3}, {5, 3}, {9, 0}, {-1, 0}} },
{"foo, bar, ", 3, {{0, 3}, {5, 3}, {9, 0}, {-1, 0}} },
{",foo,bar,", 4, {{0, 0}, {1, 3}, {5, 3}, {9, 0}} },
};

HTTPHdr hdr;
Expand Down Expand Up @@ -1899,43 +1896,43 @@ TEST_CASE("HdrTest", "[proxy][hdrtest]")
const char *slice;
const char *new_raw;
} tests[] = {
{"a,b,c", 0, "fred", "fred, b, c" },
{"a,b,c", 1, "fred", "a, fred, c" },
{"a,b,c", 2, "fred", "a, b, fred" },
{"a,b,c", 3, "fred", "a,b,c" },
{"", 0, "", "" },
{"", 0, "foo", "foo" },
{"", 1, "foo", "" },
{" ", 0, "", "" },
{" ", 0, "foo", "foo" },
{" ", 1, "foo", " " },
{",", 0, "foo", "foo, " },
{",", 1, "foo", ", foo" },
{",,", 0, "foo", "foo, , " },
{",,", 1, "foo", ", foo, " },
{",,", 2, "foo", ", , foo" },
{"foo", 0, "abc", "abc" },
{"foo", 1, "abc", "foo" },
{"foo", 0, "abc,", "abc," },
{"foo", 0, ",abc", ",abc" },
{",,", 1, ",,,", ", ,,,, " },
{" a , b , c", 0, "fred", "fred, b, c" },
{" a , b , c", 1, "fred", "a, fred, c" },
{" a , b , c", 2, "fred", "a, b, fred" },
{" a , b , c", 3, "fred", " a , b , c" },
{" a , b ", 0, "fred", "fred, b" },
{" a , b ", 1, "fred", "a, fred" },
{" a , b ", 1, "fred", "a, fred" },
{" a ,b ", 1, "fred", "a, fred" },
{"a, , , , e, , g,", 0, "fred", "fred, , , , e, , g, " },
{"a, , , , e, , g,", 1, "fred", "a, fred, , , e, , g, "},
{"a, , , , e, , g,", 2, "fred", "a, , fred, , e, , g, "},
{"a, , , , e, , g,", 5, "fred", "a, , , , e, fred, g, "},
{"a, , , , e, , g,", 7, "fred", "a, , , , e, , g, fred"},
{"a, , , , e, , g,", 8, "fred", "a, , , , e, , g," },
{"a, \"boo,foo\", c", 0, "wawa", "wawa, \"boo,foo\", c" },
{"a, \"boo,foo\", c", 1, "wawa", "a, wawa, c" },
{"a, \"boo,foo\", c", 2, "wawa", "a, \"boo,foo\", wawa" },
{"a,b,c", 0, "fred", "fred, b, c" },
{"a,b,c", 1, "fred", "a, fred, c" },
{"a,b,c", 2, "fred", "a, b, fred" },
{"a,b,c", 3, "fred", "a,b,c" },
{"", 0, "", "" },
{"", 0, "foo", "foo" },
{"", 1, "foo", "" },
{" ", 0, "", "" },
{" ", 0, "foo", "foo" },
{" ", 1, "foo", " " },
{",", 0, "foo", "foo, " },
{",", 1, "foo", ", foo" },
{",,", 0, "foo", "foo, , " },
{",,", 1, "foo", ", foo, " },
{",,", 2, "foo", ", , foo" },
{"foo", 0, "abc", "abc" },
{"foo", 1, "abc", "foo" },
{"foo", 0, "abc,", "abc," },
{"foo", 0, ",abc", ",abc" },
{",,", 1, ",,,", ", ,,,, " },
{" a , b , c", 0, "fred", "fred, b, c" },
{" a , b , c", 1, "fred", "a, fred, c" },
{" a , b , c", 2, "fred", "a, b, fred" },
{" a , b , c", 3, "fred", " a , b , c" },
{" a , b ", 0, "fred", "fred, b" },
{" a , b ", 1, "fred", "a, fred" },
{" a , b ", 1, "fred", "a, fred" },
{" a ,b ", 1, "fred", "a, fred" },
{"a, , , , e, , g,", 0, "fred", "fred, , , , e, , g, " },
{"a, , , , e, , g,", 1, "fred", "a, fred, , , e, , g, "},
{"a, , , , e, , g,", 2, "fred", "a, , fred, , e, , g, "},
{"a, , , , e, , g,", 5, "fred", "a, , , , e, fred, g, "},
{"a, , , , e, , g,", 7, "fred", "a, , , , e, , g, fred"},
{"a, , , , e, , g,", 8, "fred", "a, , , , e, , g," },
{R"(a, "boo,foo", c)", 0, "wawa", R"(wawa, "boo,foo", c)"},
{R"(a, "boo,foo", c)", 1, "wawa", "a, wawa, c" },
{R"(a, "boo,foo", c)", 2, "wawa", R"(a, "boo,foo", wawa)"},
};

HTTPHdr hdr;
Expand Down Expand Up @@ -1990,42 +1987,43 @@ TEST_CASE("HdrTest", "[proxy][hdrtest]")
int len;
} pieces[3];
} tests[] = {
{"", 1, {{0, 0}, {-1, 0}, {-1, 0}}},
{",", 2, {{0, 0}, {1, 0}, {-1, 0}} },
{" ,", 2, {{0, 0}, {2, 0}, {-1, 0}} },
{", ", 2, {{0, 0}, {1, 0}, {-1, 0}} },
{" , ", 2, {{0, 0}, {2, 0}, {-1, 0}} },
{"abc,", 2, {{0, 3}, {4, 0}, {-1, 0}} },
{"abc, ", 2, {{0, 3}, {4, 0}, {-1, 0}} },
{"", 1, {{0, 0}, {-1, 0}, {-1, 0}}},
{" ", 1, {{0, 0}, {-1, 0}, {-1, 0}}},
{" ", 1, {{0, 0}, {-1, 0}, {-1, 0}}},
{"a", 1, {{0, 1}, {-1, 0}, {-1, 0}}},
{" a", 1, {{1, 1}, {-1, 0}, {-1, 0}}},
{" a ", 1, {{2, 1}, {-1, 0}, {-1, 0}}},
{"abc,defg", 2, {{0, 3}, {4, 4}, {-1, 0}} },
{" abc,defg", 2, {{1, 3}, {5, 4}, {-1, 0}} },
{" abc, defg", 2, {{1, 3}, {6, 4}, {-1, 0}} },
{" abc , defg", 2, {{1, 3}, {7, 4}, {-1, 0}} },
{" abc , defg ", 2, {{1, 3}, {7, 4}, {-1, 0}} },
{" abc , defg, ", 3, {{1, 3}, {7, 4}, {12, 0}} },
{" abc , defg ,", 3, {{1, 3}, {7, 4}, {13, 0}} },
{", abc , defg ", 3, {{0, 0}, {2, 3}, {8, 4}} },
{" ,abc , defg ", 3, {{0, 0}, {2, 3}, {8, 4}} },
{"a,b", 2, {{0, 1}, {2, 1}, {-1, 0}} },
{"a,,b", 3, {{0, 1}, {2, 0}, {3, 1}} },
{"a, ,b", 3, {{0, 1}, {2, 0}, {4, 1}} },
{"a ,,b", 3, {{0, 1}, {3, 0}, {4, 1}} },
{",", 2, {{0, 0}, {1, 0}, {-1, 0}} },
{" ,", 2, {{0, 0}, {2, 0}, {-1, 0}} },
{", ", 2, {{0, 0}, {1, 0}, {-1, 0}} },
{" , ", 2, {{0, 0}, {2, 0}, {-1, 0}} },
{"a,b,", 3, {{0, 1}, {2, 1}, {4, 0}} },
{"a,b, ", 3, {{0, 1}, {2, 1}, {4, 0}} },
{"a,b, ", 3, {{0, 1}, {2, 1}, {4, 0}} },
{"a,b, c", 3, {{0, 1}, {2, 1}, {6, 1}} },
{"a,b, c ", 3, {{0, 1}, {2, 1}, {6, 1}} },
{"a,\"b,c\",d", 3, {{0, 1}, {3, 3}, {8, 1}} },
{"", 1, {{0, 0}, {-1, 0}, {-1, 0}}},
{",", 2, {{0, 0}, {1, 0}, {-1, 0}} },
{" ,", 2, {{0, 0}, {2, 0}, {-1, 0}} },
{", ", 2, {{0, 0}, {1, 0}, {-1, 0}} },
{" , ", 2, {{0, 0}, {2, 0}, {-1, 0}} },
{"abc,", 2, {{0, 3}, {4, 0}, {-1, 0}} },
{"abc, ", 2, {{0, 3}, {4, 0}, {-1, 0}} },
{"", 1, {{0, 0}, {-1, 0}, {-1, 0}}},
{" ", 1, {{0, 0}, {-1, 0}, {-1, 0}}},
{" ", 1, {{0, 0}, {-1, 0}, {-1, 0}}},
{"a", 1, {{0, 1}, {-1, 0}, {-1, 0}}},
{" a", 1, {{1, 1}, {-1, 0}, {-1, 0}}},
{" a ", 1, {{2, 1}, {-1, 0}, {-1, 0}}},
{"abc,defg", 2, {{0, 3}, {4, 4}, {-1, 0}} },
{" abc,defg", 2, {{1, 3}, {5, 4}, {-1, 0}} },
{" abc, defg", 2, {{1, 3}, {6, 4}, {-1, 0}} },
{" abc , defg", 2, {{1, 3}, {7, 4}, {-1, 0}} },
{" abc , defg ", 2, {{1, 3}, {7, 4}, {-1, 0}} },
{" abc , defg, ", 3, {{1, 3}, {7, 4}, {12, 0}} },
{" abc , defg ,", 3, {{1, 3}, {7, 4}, {13, 0}} },
{", abc , defg ", 3, {{0, 0}, {2, 3}, {8, 4}} },
{" ,abc , defg ", 3, {{0, 0}, {2, 3}, {8, 4}} },
{"a,b", 2, {{0, 1}, {2, 1}, {-1, 0}} },
{"a,,b", 3, {{0, 1}, {2, 0}, {3, 1}} },
{"a, ,b", 3, {{0, 1}, {2, 0}, {4, 1}} },
{"a ,,b", 3, {{0, 1}, {3, 0}, {4, 1}} },
{",", 2, {{0, 0}, {1, 0}, {-1, 0}} },
{" ,", 2, {{0, 0}, {2, 0}, {-1, 0}} },
{", ", 2, {{0, 0}, {1, 0}, {-1, 0}} },
{" , ", 2, {{0, 0}, {2, 0}, {-1, 0}} },
{"a,b,", 3, {{0, 1}, {2, 1}, {4, 0}} },
{"a,b, ", 3, {{0, 1}, {2, 1}, {4, 0}} },
{"a,b, ", 3, {{0, 1}, {2, 1}, {4, 0}} },
{"a,b, c", 3, {{0, 1}, {2, 1}, {6, 1}} },
{"a,b, c ", 3, {{0, 1}, {2, 1}, {6, 1}} },
{R"(a,"b,c",d)", 3, {{0, 1}, {3, 3}, {8, 1}} },
{R"(a,b,c="d,e")", 3, {{0, 1}, {2, 1}, {4, 7}} },
};

int i, j, ntests, offset;
Expand Down