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

Unified Diff: net/http/http_util_unittest.cc

Issue 7796025: Don't interpret embeded NULLs in a response header line as a line terminator. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address wtc comments Created 9 years, 3 months 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
===================================================================
--- net/http/http_util_unittest.cc (revision 100642)
+++ net/http/http_util_unittest.cc (working copy)
@@ -195,7 +195,7 @@
TEST(HttpUtilTest, AssembleRawHeaders) {
struct {
- const char* input;
+ const char* input; // with '|' representing '\0'
const char* expected_result; // with '\0' changed to '|'
} tests[] = {
{ "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n",
@@ -482,12 +482,26 @@
"Bar: 2||",
},
+ // Embed NULLs in the status line. They should not be understood
+ // as line separators.
+ {
+ "HTTP/1.0 200 OK|Bar2:0|Baz2:1\r\nFoo: 1\r\nBar: 2\r\n\r\n",
+ "HTTP/1.0 200 OKBar2:0Baz2:1|Foo: 1|Bar: 2||"
+ },
+
+ // Embed NULLs in a header line. They should not be understood as
+ // line separators.
+ {
+ "HTTP/1.0 200 OK\nFoo: 1|Foo2: 3\nBar: 2\n\n",
+ "HTTP/1.0 200 OK|Foo: 1Foo2: 3|Bar: 2||"
+ },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- int input_len = static_cast<int>(strlen(tests[i].input));
- std::string raw = HttpUtil::AssembleRawHeaders(tests[i].input, input_len);
+ std::string input = tests[i].input;
+ std::replace(input.begin(), input.end(), '|', '\0');
+ std::string raw = HttpUtil::AssembleRawHeaders(input.data(), input.size());
std::replace(raw.begin(), raw.end(), '\0', '|');
- EXPECT_TRUE(raw == tests[i].expected_result);
+ EXPECT_EQ(tests[i].expected_result, raw);
}
}
« 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