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

Unified Diff: net/ftp/ftp_directory_listing_parser.cc

Issue 11470035: FTP: correctly handle newlines in file names (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed \r Created 8 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/data/ftp/dir-listing-windows-2.expected ('k') | net/ftp/ftp_directory_listing_parser_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3cacee07619e59d93bc0e9f286811226ac9ba30c 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" };
+
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;
+ }
}
}
« no previous file with comments | « net/data/ftp/dir-listing-windows-2.expected ('k') | net/ftp/ftp_directory_listing_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698