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

Unified Diff: net/base/filename_util_internal.cc

Issue 640713002: Generated FIlename different from Content Disposition string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unittests Created 6 years, 2 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 | « no previous file | net/base/filename_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/filename_util_internal.cc
diff --git a/net/base/filename_util_internal.cc b/net/base/filename_util_internal.cc
index 49b6a3db923d52fef031f1a666563422241dc793..cda7f62c01c8896d01d007585b02b0a8e3f97d36 100644
--- a/net/base/filename_util_internal.cc
+++ b/net/base/filename_util_internal.cc
@@ -229,11 +229,13 @@ base::string16 GetSuggestedFilenameImpl(
FILE_PATH_LITERAL("download");
std::string filename; // In UTF-8
bool overwrite_extension = false;
-
+ bool is_name_from_content_disposition = false;
// Try to extract a filename from content-disposition first.
if (!content_disposition.empty()) {
HttpContentDisposition header(content_disposition, referrer_charset);
filename = header.filename();
+ if (!filename.empty())
+ is_name_from_content_disposition = true;
}
// Then try to use the suggested name.
@@ -275,7 +277,13 @@ base::string16 GetSuggestedFilenameImpl(
}
replace_illegal_characters_callback.Run(&result_str, '-');
base::FilePath result(result_str);
- GenerateSafeFileName(mime_type, overwrite_extension, &result);
+ // extension should not appended to filename derived from
+ // content-disposition, if it does not have one.
+ // Hence mimetype and overwrite_extension values are not used.
+ if (is_name_from_content_disposition)
+ GenerateSafeFileName("", false, &result);
+ else
+ GenerateSafeFileName(mime_type, overwrite_extension, &result);
base::string16 result16;
if (!FilePathToString16(result, &result16)) {
« no previous file with comments | « no previous file | net/base/filename_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698