Chromium Code Reviews| Index: net/ftp/ftp_directory_listing_parser.cc |
| diff --git a/net/ftp/ftp_directory_listing_parser.cc b/net/ftp/ftp_directory_listing_parser.cc |
| index d7c7c7d3b281cb84b6c271d926868a8588271392..ed69a4fea37ef3093803a165fa6dc7c559734798 100644 |
| --- a/net/ftp/ftp_directory_listing_parser.cc |
| +++ b/net/ftp/ftp_directory_listing_parser.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/stl_util.h" |
| #include "base/string_split.h" |
| #include "base/string_util.h" |
| +#include "base/utf_string_conversions.h" |
| #include "net/base/net_errors.h" |
| #include "net/ftp/ftp_directory_listing_parser_ls.h" |
| #include "net/ftp/ftp_directory_listing_parser_netware.h" |
| @@ -41,12 +42,13 @@ int FillInRawName(const std::string& encoding, |
| // Parses |text| as an FTP directory listing. Fills in |entries| |
| // and |server_type| and returns network error code. |
| int ParseListing(const string16& text, |
| + const string16& newline_separator, |
| const std::string& encoding, |
| const base::Time& current_time, |
| std::vector<FtpDirectoryListingEntry>* entries, |
| FtpServerType* server_type) { |
| std::vector<string16> lines; |
| - base::SplitString(text, '\n', &lines); |
| + base::SplitStringUsingSubstr(text, newline_separator, &lines); |
| struct { |
| base::Callback<bool(void)> callback; |
| @@ -93,6 +95,8 @@ int DecodeAndParse(const std::string& text, |
| const base::Time& current_time, |
| std::vector<FtpDirectoryListingEntry>* entries, |
| FtpServerType* server_type) { |
| + const char* kNewlineSeparators[] = { "\n", "\r\n", "\r" }; |
|
mmenke
2012/12/12 17:20:44
SplitString trims whitespace, so if |text| only ha
mmenke
2012/12/12 17:20:44
If we run into a server that uses "\r"-style lineb
Paweł Hajdan Jr.
2012/12/12 18:26:19
That's exactly what the bug is about. :)
Paweł Hajdan Jr.
2012/12/12 18:26:19
Good point. I just removed "\r" then. I haven't ye
mmenke
2012/12/12 18:36:12
Oops - didn't see the bug.
|
| + |
| std::vector<std::string> encodings; |
| if (!base::DetectAllEncodings(text, &encodings)) |
| return ERR_ENCODING_DETECTION_FAILED; |
| @@ -104,13 +108,16 @@ int DecodeAndParse(const std::string& text, |
| encodings[i].c_str(), |
| base::OnStringConversionError::FAIL, |
| &converted_text)) { |
| - int rv = ParseListing(converted_text, |
| - encodings[i], |
| - current_time, |
| - entries, |
| - server_type); |
| - if (rv == OK) |
| - return rv; |
| + for (size_t j = 0; j < arraysize(kNewlineSeparators); j++) { |
| + int rv = ParseListing(converted_text, |
| + ASCIIToUTF16(kNewlineSeparators[j]), |
| + encodings[i], |
| + current_time, |
| + entries, |
| + server_type); |
| + if (rv == OK) |
| + return rv; |
| + } |
| } |
| } |