Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1549)

Unified Diff: net/http/http_util_unittest.cc

Issue 2555813002: Don't consider '\0' as whitespace when parsing HTTP headers. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/http/http_util.cc ('K') | « net/http/http_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_util_unittest.cc
diff --git a/net/http/http_util_unittest.cc b/net/http/http_util_unittest.cc
index f2c2146215ecc645bbea998d1cd7cd8002b82d0f..1ed04857c57f570ad36db6b6d19ab5fd2054221a 100644
--- a/net/http/http_util_unittest.cc
+++ b/net/http/http_util_unittest.cc
@@ -378,6 +378,7 @@ TEST(HttpUtilTest, LocateEndOfAdditionalHeaders) {
}
}
TEST(HttpUtilTest, AssembleRawHeaders) {
+ // clang-format off
struct {
const char* const input; // with '|' representing '\0'
const char* const expected_result; // with '\0' changed to '|'
@@ -679,7 +680,18 @@ TEST(HttpUtilTest, AssembleRawHeaders) {
"HTTP/1.0 200 OK\nFoo: 1|Foo2: 3\nBar: 2\n\n",
"HTTP/1.0 200 OK|Foo: 1Foo2: 3|Bar: 2||"
},
+
+ // An embedded NUL should not be interpreted as LWS (leading to line
+ // continuations)
+ {
+ "HTTP/1.0 200 OK\n"
+ "Foo: 1\n"
+ "|EmbeddedNull: 3\n"
+ "Bar: 2\n\n",
+ "HTTP/1.0 200 OK|Foo: 1|EmbeddedNull: 3|Bar: 2||"
mmenke 2016/12/06 19:08:24 EmbeddedNull? Where's the magic for that.
eroman 2016/12/06 19:19:34 There is nothing special about "EmbeddedNull", I j
eroman 2016/12/06 19:25:33 Want me to rename this to something more generic l
eroman 2016/12/06 19:29:00 Done.
+ },
};
+ // clang-format on
for (size_t i = 0; i < arraysize(tests); ++i) {
std::string input = tests[i].input;
std::replace(input.begin(), input.end(), '|', '\0');
@@ -1408,4 +1420,17 @@ TEST(HttpUtilTest, IsToken) {
EXPECT_FALSE(HttpUtil::IsToken("\xff"));
}
+TEST(HttpUtilTest, IsLWS) {
+ EXPECT_FALSE(HttpUtil::IsLWS('\v'));
+ EXPECT_FALSE(HttpUtil::IsLWS('\0'));
+ EXPECT_FALSE(HttpUtil::IsLWS('1'));
+ EXPECT_FALSE(HttpUtil::IsLWS('a'));
+ EXPECT_FALSE(HttpUtil::IsLWS('.'));
+ EXPECT_FALSE(HttpUtil::IsLWS('\n'));
+ EXPECT_FALSE(HttpUtil::IsLWS('\r'));
+
+ EXPECT_TRUE(HttpUtil::IsLWS('\t'));
+ EXPECT_TRUE(HttpUtil::IsLWS(' '));
mmenke 2016/12/06 19:08:24 Should we have a whitelist here? i.e. for (int c
eroman 2016/12/06 19:19:34 I think that is a bit overkill, but can switch to
mmenke 2016/12/06 19:25:29 ok
+}
+
} // namespace net
« net/http/http_util.cc ('K') | « net/http/http_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698