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

Unified Diff: net/http/http_util_unittest.cc

Issue 2555813002: Don't consider '\0' as whitespace when parsing HTTP headers. (Closed)
Patch Set: EmbeddedNull --> Blah (and update comment) 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
« no previous file with comments | « 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..699739ff0f3634525922c928ff82372d12835e76 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,19 @@ 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||"
},
+
+ // The embedded NUL at the start of the line (before "Blah:") should not be
+ // interpreted as LWS (as that would mistake it for a header line
+ // continuation).
+ {
+ "HTTP/1.0 200 OK\n"
+ "Foo: 1\n"
+ "|Blah: 3\n"
+ "Bar: 2\n\n",
+ "HTTP/1.0 200 OK|Foo: 1|Blah: 3|Bar: 2||"
+ },
};
+ // 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 +1421,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(' '));
+}
+
} // namespace net
« no previous file with comments | « net/http/http_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698