This is an automated email from the ASF dual-hosted git repository.
bnolsen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 28458b72c mime header field parsing fix trailing quote handlling
(#9513)
28458b72c is described below
commit 28458b72c4937f207aadf101fd3af9a6b7ae3776
Author: Brian Olsen <[email protected]>
AuthorDate: Fri Mar 24 07:17:56 2023 -0600
mime header field parsing fix trailing quote handlling (#9513)
Co-authored-by: Brian Olsen <[email protected]>
---
proxy/hdrs/HttpCompat.cc | 14 +--
proxy/hdrs/unit_tests/test_Hdrs.cc | 188 ++++++++++++++++++-------------------
2 files changed, 101 insertions(+), 101 deletions(-)
diff --git a/proxy/hdrs/HttpCompat.cc b/proxy/hdrs/HttpCompat.cc
index 8964ab333..03663ee8e 100644
--- a/proxy/hdrs/HttpCompat.cc
+++ b/proxy/hdrs/HttpCompat.cc
@@ -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;
@@ -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)) {
@@ -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
}
diff --git a/proxy/hdrs/unit_tests/test_Hdrs.cc
b/proxy/hdrs/unit_tests/test_Hdrs.cc
index 2419fdd04..3ce78a004 100644
--- a/proxy/hdrs/unit_tests/test_Hdrs.cc
+++ b/proxy/hdrs/unit_tests/test_Hdrs.cc
@@ -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;
@@ -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;
@@ -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;