summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authorrolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 04:18:58 +0000
committerrolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 04:18:58 +0000
commitfcb7fd9e3fb31998c9055c63a6b99024e97f211e (patch)
tree9bd2297b3a58e4e345d17f868f0cc7072b1ef3bc /net/base
parent204758c792daa561ccf691ecd101e6360540360f (diff)
downloadchromium_src-fcb7fd9e3fb31998c9055c63a6b99024e97f211e.zip
chromium_src-fcb7fd9e3fb31998c9055c63a6b99024e97f211e.tar.gz
chromium_src-fcb7fd9e3fb31998c9055c63a6b99024e97f211e.tar.bz2
Moved patch from 297003 over to committer repository.
Review: http://codereview.chromium.org/297003 BUG=24846 TEST=URLRequestTest.DataURLImageTest, NetUtilTest.GetSuggestedFilename git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/net_util.cc15
-rw-r--r--net/base/net_util_unittest.cc16
2 files changed, 30 insertions, 1 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 05f5841..f75184f 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1036,6 +1036,18 @@ std::wstring GetSuggestedFilename(const GURL& url,
const std::string& content_disposition,
const std::string& referrer_charset,
const std::wstring& default_name) {
+ // TODO(rolandsteiner): as pointed out by darin in the code review, this is
+ // hardly ideal. "download" should be translated, or another solution found.
+ // (cf. http://code.google.com/p/chromium/issues/detail?id=25289)
+ const wchar_t kFinalFallbackName[] = L"download";
+
+ // about: and data: URLs don't have file names, but esp. data: URLs may
+ // contain parts that look like ones (i.e., contain a slash).
+ // Therefore we don't attempt to divine a file name out of them.
+ if (url.SchemeIs("about") || url.SchemeIs("data"))
+ return default_name.empty() ? std::wstring(kFinalFallbackName)
+ : default_name;
+
std::wstring filename = GetFileNameFromCD(content_disposition,
referrer_charset);
if (!filename.empty()) {
@@ -1065,7 +1077,8 @@ std::wstring GetSuggestedFilename(const GURL& url,
// Some schemes (e.g. file) do not have a hostname. Even though it's
// not likely to reach here, let's hardcode the last fallback name.
// TODO(jungshik) : Decode a 'punycoded' IDN hostname. (bug 1264451)
- filename = url.host().empty() ? L"download" : UTF8ToWide(url.host());
+ filename = url.host().empty() ? std::wstring(kFinalFallbackName)
+ : UTF8ToWide(url.host());
} else {
NOTREACHED();
}
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 22d467c..eddbd16 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -972,6 +972,22 @@ TEST(NetUtilTest, GetSuggestedFilename) {
"",
L"",
L"test.html"},
+ // about: and data: URLs
+ {"about:chrome",
+ "",
+ "",
+ L"",
+ L"download"},
+ {"data:,looks/like/a.path",
+ "",
+ "",
+ L"",
+ L"download"},
+ {"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=",
+ "",
+ "",
+ L"",
+ L"download"},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
std::wstring filename = net::GetSuggestedFilename(