summaryrefslogtreecommitdiffstats
path: root/net/ftp
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-17 17:50:04 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-17 17:50:04 +0000
commit90a4028e5f7b6bea04220d61ebc9ebae85771264 (patch)
treee0c1fa3b8a2c493f2f01f8a7ab5e862dc008afc3 /net/ftp
parent404f9b08934f6649ee9f6d5ee610aac1e2692a03 (diff)
downloadchromium_src-90a4028e5f7b6bea04220d61ebc9ebae85771264.zip
chromium_src-90a4028e5f7b6bea04220d61ebc9ebae85771264.tar.gz
chromium_src-90a4028e5f7b6bea04220d61ebc9ebae85771264.tar.bz2
FTP: Fix Windows directory listing parser for empty file names.
BUG=66097 TEST=net_unittests Review URL: http://codereview.chromium.org/5688005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69558 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r--net/ftp/ftp_directory_listing_parser_windows.cc25
-rw-r--r--net/ftp/ftp_directory_listing_parser_windows_unittest.cc27
2 files changed, 45 insertions, 7 deletions
diff --git a/net/ftp/ftp_directory_listing_parser_windows.cc b/net/ftp/ftp_directory_listing_parser_windows.cc
index 7bce556..ef733d5 100644
--- a/net/ftp/ftp_directory_listing_parser_windows.cc
+++ b/net/ftp/ftp_directory_listing_parser_windows.cc
@@ -15,7 +15,7 @@ namespace {
bool WindowsDateListingToTime(const std::vector<string16>& columns,
base::Time* time) {
- DCHECK_LE(4U, columns.size());
+ DCHECK_LE(3U, columns.size());
base::Time::Exploded time_exploded = { 0 };
@@ -84,15 +84,18 @@ bool FtpDirectoryListingParserWindows::ConsumeLine(const string16& line) {
std::vector<string16> columns;
base::SplitString(CollapseWhitespace(line, false), ' ', &columns);
- // We may receive file names containing spaces, which can make the number of
- // columns arbitrarily large. We will handle that later. For now just make
- // sure we have all the columns that should normally be there.
- if (columns.size() < 4)
+ // Every line of the listing consists of the following:
+ //
+ // 1. date
+ // 2. time
+ // 3. size in bytes (or "<DIR>" for directories)
+ // 4. filename (may be empty or contain spaces)
+ //
+ // For now, make sure we have 1-3, and handle 4 later.
+ if (columns.size() < 3)
return false;
FtpDirectoryListingEntry entry;
- entry.name = FtpUtil::GetStringPartAfterColumns(line, 3);
-
if (EqualsASCII(columns[2], "<DIR>")) {
entry.type = FtpDirectoryListingEntry::DIRECTORY;
entry.size = -1;
@@ -107,6 +110,14 @@ bool FtpDirectoryListingParserWindows::ConsumeLine(const string16& line) {
if (!WindowsDateListingToTime(columns, &entry.last_modified))
return false;
+ entry.name = FtpUtil::GetStringPartAfterColumns(line, 3);
+ if (entry.name.empty()) {
+ // Some FTP servers send listing entries with empty names. It's not obvious
+ // how to display such an entry, so we ignore them. We don't want to make
+ // the parsing fail at this point though. Other entries can still be useful.
+ return true;
+ }
+
entries_.push(entry);
return true;
}
diff --git a/net/ftp/ftp_directory_listing_parser_windows_unittest.cc b/net/ftp/ftp_directory_listing_parser_windows_unittest.cc
index 60309cb..aeb64e7 100644
--- a/net/ftp/ftp_directory_listing_parser_windows_unittest.cc
+++ b/net/ftp/ftp_directory_listing_parser_windows_unittest.cc
@@ -64,15 +64,42 @@ TEST_F(FtpDirectoryListingParserWindowsTest, Good) {
}
}
+TEST_F(FtpDirectoryListingParserWindowsTest, Ignored) {
+ const char* ignored_cases[] = {
+ "12-07-10 12:05AM <DIR> ", // http://crbug.com/66097
+ "12-07-10 12:05AM 1234 ",
+ };
+ for (size_t i = 0; i < arraysize(ignored_cases); i++) {
+ SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
+ ignored_cases[i]));
+
+ net::FtpDirectoryListingParserWindows parser;
+ EXPECT_TRUE(parser.ConsumeLine(UTF8ToUTF16(ignored_cases[i])));
+ EXPECT_FALSE(parser.EntryAvailable());
+ EXPECT_TRUE(parser.OnEndOfInput());
+ EXPECT_FALSE(parser.EntryAvailable());
+ }
+}
+
TEST_F(FtpDirectoryListingParserWindowsTest, Bad) {
const char* bad_cases[] = {
"",
"garbage",
+ "11-02-09 05:32PM <GARBAGE>",
"11-02-09 05:32PM <GARBAGE> NT",
+ "11-02-09 05:32 <DIR>",
+ "11-FEB-09 05:32PM <DIR>",
+ "11-02 05:32PM <DIR>",
+ "11-02-09 05:32PM -1",
"11-02-09 05:32 <DIR> NT",
"11-FEB-09 05:32PM <DIR> NT",
"11-02 05:32PM <DIR> NT",
"11-02-09 05:32PM -1 NT",
+ "99-25-10 12:00AM 0",
+ "12-99-10 12:00AM 0",
+ "12-25-10 99:00AM 0",
+ "12-25-10 12:99AM 0",
+ "12-25-10 12:00ZM 0",
"99-25-10 12:00AM 0 months out of range",
"12-99-10 12:00AM 0 days out of range",
"12-25-10 99:00AM 0 hours out of range",