summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc10
-rw-r--r--net/base/net_util_unittest.cc35
2 files changed, 42 insertions, 3 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index df012a2..aa01f1f 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -819,9 +819,13 @@ std::string GetDirectoryListingEntry(const std::string& name,
result.append(",");
- Time time(Time::FromFileTime(*modified));
- string_escape::JavascriptDoubleQuote(base::TimeFormatShortDateAndTime(time),
- true, &result);
+ std::wstring modified_str;
+ // |modified| can be NULL in FTP listings.
+ if (modified) {
+ Time time(Time::FromFileTime(*modified));
+ modified_str = base::TimeFormatShortDateAndTime(time);
+ }
+ string_escape::JavascriptDoubleQuote(modified_str, true, &result);
result.append(");</script>\n");
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 94017fc..954afad 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -698,3 +698,38 @@ TEST(NetUtilTest, GetSuggestedFilename) {
}
}
+// This is currently a windows specific function.
+#if defined(OS_WIN)
+namespace {
+
+struct GetDirectoryListingEntryCase {
+ const char* name;
+ DWORD file_attrib;
+ int64 filesize;
+ FILETIME* modified;
+ const char* expected;
+};
+
+} // namespace
+TEST(NetUtilTest, GetDirectoryListingEntry) {
+ const GetDirectoryListingEntryCase test_cases[] = {
+ {"Foo",
+ 0,
+ 10000,
+ NULL,
+ "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"},
+ {"quo\"tes",
+ 0,
+ 10000,
+ NULL,
+ "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>\n"},
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
+ const std::string results = net::GetDirectoryListingEntry(
+ test_cases[i].name, test_cases[i].file_attrib,
+ test_cases[i].filesize, test_cases[i].modified);
+ EXPECT_EQ(test_cases[i].expected, results);
+ }
+}
+#endif