diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-27 02:43:20 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-27 02:43:20 +0000 |
commit | e2419084a9f703f8f1a754ab38b4fcfd61e08225 (patch) | |
tree | 7d6ffa10a2e712898fb7e874ddcf899fef74c1a4 /net | |
parent | 1ea7c844992d80d402b98f2fcc37d4be7121920d (diff) | |
download | chromium_src-e2419084a9f703f8f1a754ab38b4fcfd61e08225.zip chromium_src-e2419084a9f703f8f1a754ab38b4fcfd61e08225.tar.gz chromium_src-e2419084a9f703f8f1a754ab38b4fcfd61e08225.tar.bz2 |
Fix a bug with parsing ftp directory listing lines.
BUG=49997
TEST=ftp_directory_listing_parser_windows_unittest.cc
Review URL: http://codereview.chromium.org/3013029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53747 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/ftp/ftp_directory_listing_parser_windows.cc | 13 | ||||
-rw-r--r-- | net/ftp/ftp_directory_listing_parser_windows_unittest.cc | 11 |
2 files changed, 21 insertions, 3 deletions
diff --git a/net/ftp/ftp_directory_listing_parser_windows.cc b/net/ftp/ftp_directory_listing_parser_windows.cc index 85ae6d5..890ffc5 100644 --- a/net/ftp/ftp_directory_listing_parser_windows.cc +++ b/net/ftp/ftp_directory_listing_parser_windows.cc @@ -48,11 +48,18 @@ bool WindowsDateListingToTime(const std::vector<string16>& columns, return false; if (!StringToInt(time_parts[1], &time_exploded.minute)) return false; + if (!time_exploded.HasValidValues()) + return false; string16 am_or_pm(columns[1].substr(5, 2)); - if (EqualsASCII(am_or_pm, "PM")) - time_exploded.hour += 12; - else if (!EqualsASCII(am_or_pm, "AM")) + if (EqualsASCII(am_or_pm, "PM")) { + if (time_exploded.hour < 12) + time_exploded.hour += 12; + } else if (EqualsASCII(am_or_pm, "AM")) { + if (time_exploded.hour == 12) + time_exploded.hour = 0; + } else { return false; + } // We don't know the time zone of the server, so just use local time. *time = base::Time::FromLocalExploded(time_exploded); diff --git a/net/ftp/ftp_directory_listing_parser_windows_unittest.cc b/net/ftp/ftp_directory_listing_parser_windows_unittest.cc index a768d05..eaf48ca 100644 --- a/net/ftp/ftp_directory_listing_parser_windows_unittest.cc +++ b/net/ftp/ftp_directory_listing_parser_windows_unittest.cc @@ -50,6 +50,12 @@ TEST_F(FtpDirectoryListingParserWindowsTest, Good) { { "11-02-09 05:32PM <DIR> My Directory", net::FtpDirectoryListingEntry::DIRECTORY, "My Directory", -1, 2009, 11, 2, 17, 32 }, + { "12-25-10 12:00AM <DIR> Christmas Midnight", + net::FtpDirectoryListingEntry::DIRECTORY, "Christmas Midnight", -1, + 2010, 12, 25, 0, 0 }, + { "12-25-10 12:00PM <DIR> Christmas Midday", + net::FtpDirectoryListingEntry::DIRECTORY, "Christmas Midday", -1, + 2010, 12, 25, 12, 0 }, }; for (size_t i = 0; i < arraysize(good_cases); i++) { SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, good_cases[i].input)); @@ -68,6 +74,11 @@ TEST_F(FtpDirectoryListingParserWindowsTest, Bad) { "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 months out of range", + "12-99-10 12:00AM 0 days out of range", + "12-25-10 99:00AM 0 hours out of range", + "12-25-10 12:99AM 0 minutes out of range", + "12-25-10 12:00ZM 0 what does ZM mean", }; for (size_t i = 0; i < arraysize(bad_cases); i++) { net::FtpDirectoryListingParserWindows parser; |