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

Unified Diff: net/base/net_util.cc

Issue 2733005: Download filename encoding fix [try2]: (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: add test Created 10 years, 6 months 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 | « chrome/browser/gtk/download_item_gtk.cc ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 60f626d44cec4bbd9c223475485c35f912923523..5eb2e68f4648f417f186d56503643bba7c2eccb8 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -272,6 +272,11 @@ bool DecodeWord(const std::string& encoded_word,
const std::string& referrer_charset,
bool* is_rfc2047,
std::string* output) {
+ *is_rfc2047 = false;
+ output->clear();
+ if (encoded_word.empty())
+ return true;
+
if (!IsStringASCII(encoded_word)) {
// Try UTF-8, referrer_charset and the native OS default charset in turn.
if (IsStringUTF8(encoded_word)) {
@@ -287,7 +292,7 @@ bool DecodeWord(const std::string& encoded_word,
*output = WideToUTF8(base::SysNativeMBToWide(encoded_word));
}
}
- *is_rfc2047 = false;
+
return true;
}
@@ -1081,7 +1086,7 @@ FilePath GetSuggestedFilename(const GURL& url,
}
const std::string filename_from_cd = GetFileNameFromCD(content_disposition,
- referrer_charset);
+ referrer_charset);
#if defined(OS_WIN)
FilePath::StringType filename = UTF8ToWide(filename_from_cd);
#elif defined(OS_POSIX)
@@ -1102,10 +1107,21 @@ FilePath GetSuggestedFilename(const GURL& url,
const std::string unescaped_url_filename = UnescapeURLComponent(
url.ExtractFileName(),
UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
+
+ // The URL's path should be escaped UTF-8, but may not be.
+ std::string decoded_filename = unescaped_url_filename;
+ if (!IsStringASCII(decoded_filename)) {
+ bool ignore;
+ // TODO(jshin): this is probably not robust enough. To be sure, we
+ // need encoding detection.
+ DecodeWord(unescaped_url_filename, referrer_charset, &ignore,
+ &decoded_filename);
+ }
+
#if defined(OS_WIN)
- filename = UTF8ToWide(unescaped_url_filename);
+ filename = UTF8ToWide(decoded_filename);
#elif defined(OS_POSIX)
- filename = unescaped_url_filename;
+ filename = decoded_filename;
#endif
}
}
« no previous file with comments | « chrome/browser/gtk/download_item_gtk.cc ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698