diff options
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/multipart_response_delegate.cc | 19 | ||||
-rw-r--r-- | webkit/glue/multipart_response_delegate_unittest.cc | 13 |
2 files changed, 22 insertions, 10 deletions
diff --git a/webkit/glue/multipart_response_delegate.cc b/webkit/glue/multipart_response_delegate.cc index d7c8c29..0b37050 100644 --- a/webkit/glue/multipart_response_delegate.cc +++ b/webkit/glue/multipart_response_delegate.cc @@ -126,10 +126,21 @@ void MultipartResponseDelegate::OnReceivedData(const char* data, size_t boundary_pos; while ((boundary_pos = FindBoundary()) != std::string::npos) { if (boundary_pos > 0 && client_) { - // Send the last data chunk. - client_->didReceiveData(loader_, - data_.data(), - static_cast<int>(boundary_pos)); + // Strip out trailing \n\r characters in the buffer preceding the + // boundary on the same lines as Firefox. + size_t data_length = boundary_pos; + if (data_[boundary_pos - 1] == '\n') { + data_length--; + if (data_[boundary_pos - 2] == '\r') { + data_length--; + } + } + if (data_length > 0) { + // Send the last data chunk. + client_->didReceiveData(loader_, + data_.data(), + static_cast<int>(data_length)); + } } size_t boundary_end_pos = boundary_pos + boundary_.length(); if (boundary_end_pos < data_.length() && '-' == data_[boundary_end_pos]) { diff --git a/webkit/glue/multipart_response_delegate_unittest.cc b/webkit/glue/multipart_response_delegate_unittest.cc index 84d1e05..0433b52 100644 --- a/webkit/glue/multipart_response_delegate_unittest.cc +++ b/webkit/glue/multipart_response_delegate_unittest.cc @@ -221,7 +221,7 @@ TEST(MultipartResponseTest, MissingBoundaries) { static_cast<int>(no_start_boundary.length())); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(1, client.received_data_); - EXPECT_EQ(string("This is a sample response\n"), + EXPECT_EQ(string("This is a sample response"), client.data_); delegate.OnCompletedRequest(); @@ -287,7 +287,7 @@ TEST(MultipartResponseTest, MalformedBoundary) { delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(1, client.received_data_); - EXPECT_EQ(string("This is a sample response\n"), client.data_); + EXPECT_EQ(string("This is a sample response"), client.data_); delegate.OnCompletedRequest(); EXPECT_EQ(1, client.received_response_); @@ -304,8 +304,9 @@ struct TestChunk { const char* expected_data; }; -void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size, int responses, - int received_data, const char* completed_data) { +void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size, + int responses, int received_data, + const char* completed_data) { const string data( "--bound\n" // 0-7 "Content-type: image/png\n\n" // 8-32 @@ -618,7 +619,7 @@ TEST(MultipartResponseTest, MultipartPayloadSet) { delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); EXPECT_EQ(1, client.received_response_); - EXPECT_EQ(string("response data\n"), + EXPECT_EQ(string("response data"), client.data_); EXPECT_EQ(false, client.response_.isMultipartPayload()); @@ -629,7 +630,7 @@ TEST(MultipartResponseTest, MultipartPayloadSet) { delegate.OnReceivedData(data2.c_str(), static_cast<int>(data2.length())); EXPECT_EQ(2, client.received_response_); - EXPECT_EQ(string("response data2\n"), + EXPECT_EQ(string("response data2"), client.data_); EXPECT_EQ(true, client.response_.isMultipartPayload()); } |