| Index: net/base/filename_util.cc
|
| diff --git a/net/base/filename_util.cc b/net/base/filename_util.cc
|
| index ed4831d8b46375f6a4590a933810dfd4f857adb6..0927973913997b5b43918ef8cfbbb4d4b734545a 100644
|
| --- a/net/base/filename_util.cc
|
| +++ b/net/base/filename_util.cc
|
| @@ -77,13 +77,12 @@ std::string GetFileNameFromURL(const GURL& url,
|
| // encoding detection.
|
| base::string16 utf16_output;
|
| if (!referrer_charset.empty() &&
|
| - net::ConvertToUTF16(unescaped_url_filename,
|
| - referrer_charset.c_str(),
|
| - &utf16_output)) {
|
| + net::ConvertToUTF16(
|
| + unescaped_url_filename, referrer_charset.c_str(), &utf16_output)) {
|
| decoded_filename = base::UTF16ToUTF8(utf16_output);
|
| } else {
|
| - decoded_filename = base::WideToUTF8(
|
| - base::SysNativeMBToWide(unescaped_url_filename));
|
| + decoded_filename =
|
| + base::WideToUTF8(base::SysNativeMBToWide(unescaped_url_filename));
|
| }
|
| }
|
| // If the URL contains a (possibly empty) query, assume it is a generator, and
|
| @@ -122,10 +121,9 @@ bool IsReservedName(const base::FilePath::StringType& filename) {
|
| // I also added clock$ because GetSaveFileName seems to consider it as a
|
| // reserved name too.
|
| static const char* const known_devices[] = {
|
| - "con", "prn", "aux", "nul", "com1", "com2", "com3", "com4", "com5",
|
| - "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4",
|
| - "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "clock$"
|
| - };
|
| + "con", "prn", "aux", "nul", "com1", "com2", "com3", "com4",
|
| + "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3",
|
| + "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "clock$"};
|
| #if defined(OS_WIN)
|
| std::string filename_lower = StringToLowerASCII(base::WideToUTF8(filename));
|
| #elif defined(OS_POSIX)
|
| @@ -141,10 +139,10 @@ bool IsReservedName(const base::FilePath::StringType& filename) {
|
| return true;
|
| }
|
|
|
| - static const char* const magic_names[] = {
|
| - // These file names are used by the "Customize folder" feature of the shell.
|
| - "desktop.ini",
|
| - "thumbs.db",
|
| + static const char* const magic_names[] = {// These file names are used by the
|
| + // "Customize folder" feature of the
|
| + // shell.
|
| + "desktop.ini", "thumbs.db",
|
| };
|
|
|
| for (size_t i = 0; i < arraysize(magic_names); ++i) {
|
| @@ -155,7 +153,6 @@ bool IsReservedName(const base::FilePath::StringType& filename) {
|
| return false;
|
| }
|
|
|
| -
|
| // Examines the current extension in |file_name| and modifies it if necessary in
|
| // order to ensure the filename is safe. If |file_name| doesn't contain an
|
| // extension or if |ignore_extension| is true, then a new extension will be
|
| @@ -246,22 +243,22 @@ GURL FilePathToFileURL(const base::FilePath& path) {
|
|
|
| // must be the first substitution since others will introduce percents as the
|
| // escape character
|
| - ReplaceSubstringsAfterOffset(&url_string, 0,
|
| - FILE_PATH_LITERAL("%"), FILE_PATH_LITERAL("%25"));
|
| + ReplaceSubstringsAfterOffset(
|
| + &url_string, 0, FILE_PATH_LITERAL("%"), FILE_PATH_LITERAL("%25"));
|
|
|
| // semicolon is supposed to be some kind of separator according to RFC 2396
|
| - ReplaceSubstringsAfterOffset(&url_string, 0,
|
| - FILE_PATH_LITERAL(";"), FILE_PATH_LITERAL("%3B"));
|
| + ReplaceSubstringsAfterOffset(
|
| + &url_string, 0, FILE_PATH_LITERAL(";"), FILE_PATH_LITERAL("%3B"));
|
|
|
| - ReplaceSubstringsAfterOffset(&url_string, 0,
|
| - FILE_PATH_LITERAL("#"), FILE_PATH_LITERAL("%23"));
|
| + ReplaceSubstringsAfterOffset(
|
| + &url_string, 0, FILE_PATH_LITERAL("#"), FILE_PATH_LITERAL("%23"));
|
|
|
| - ReplaceSubstringsAfterOffset(&url_string, 0,
|
| - FILE_PATH_LITERAL("?"), FILE_PATH_LITERAL("%3F"));
|
| + ReplaceSubstringsAfterOffset(
|
| + &url_string, 0, FILE_PATH_LITERAL("?"), FILE_PATH_LITERAL("%3F"));
|
|
|
| #if defined(OS_POSIX)
|
| - ReplaceSubstringsAfterOffset(&url_string, 0,
|
| - FILE_PATH_LITERAL("\\"), FILE_PATH_LITERAL("%5C"));
|
| + ReplaceSubstringsAfterOffset(
|
| + &url_string, 0, FILE_PATH_LITERAL("\\"), FILE_PATH_LITERAL("%5C"));
|
| #endif
|
|
|
| return GURL(url_string);
|
| @@ -295,7 +292,7 @@ bool FileURLToFilePath(const GURL& url, base::FilePath* file_path) {
|
| path.append(url.path());
|
| }
|
| std::replace(path.begin(), path.end(), '/', '\\');
|
| -#else // defined(OS_WIN)
|
| +#else // defined(OS_WIN)
|
| // Firefox seems to ignore the "host" of a file url if there is one. That is,
|
| // file://foo/bar.txt maps to /bar.txt.
|
| // TODO(dhg): This should probably take into account UNCs which could
|
| @@ -307,8 +304,8 @@ bool FileURLToFilePath(const GURL& url, base::FilePath* file_path) {
|
| return false;
|
|
|
| // GURL stores strings as percent-encoded 8-bit, this will undo if possible.
|
| - path = UnescapeURLComponent(path,
|
| - UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
|
| + path = UnescapeURLComponent(
|
| + path, UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
|
|
|
| #if defined(OS_WIN)
|
| if (IsStringUTF8(path)) {
|
| @@ -326,7 +323,7 @@ bool FileURLToFilePath(const GURL& url, base::FilePath* file_path) {
|
| // string back. We detect this and report failure.
|
| file_path_str = base::SysNativeMBToWide(path);
|
| }
|
| -#else // defined(OS_WIN)
|
| +#else // defined(OS_WIN)
|
| // Collapse multiple path slashes into a single path slash.
|
| std::string new_path;
|
| do {
|
| @@ -348,14 +345,12 @@ bool IsSafePortablePathComponent(const base::FilePath& component) {
|
| base::FilePath::StringType extension = component.Extension();
|
| if (!extension.empty())
|
| extension.erase(extension.begin()); // Erase preceding '.'.
|
| - return !component.empty() &&
|
| - (component == component.BaseName()) &&
|
| + return !component.empty() && (component == component.BaseName()) &&
|
| (component == component.StripTrailingSeparators()) &&
|
| FilePathToString16(component, &component16) &&
|
| file_util::IsFilenameLegal(component16) &&
|
| !IsShellIntegratedExtension(extension) &&
|
| - (sanitized == component.value()) &&
|
| - !IsReservedName(component.value());
|
| + (sanitized == component.value()) && !IsReservedName(component.value());
|
| }
|
|
|
| bool IsSafePortableRelativePath(const base::FilePath& path) {
|
| @@ -406,7 +401,7 @@ base::string16 GetSuggestedFilename(const GURL& url,
|
| // We don't translate this fallback string, "download". If localization is
|
| // needed, the caller should provide localized fallback in |default_name|.
|
| static const base::FilePath::CharType kFinalFallbackName[] =
|
| - FILE_PATH_LITERAL("download");
|
| + FILE_PATH_LITERAL("download");
|
| std::string filename; // In UTF-8
|
| bool overwrite_extension = false;
|
|
|
| @@ -429,9 +424,7 @@ base::string16 GetSuggestedFilename(const GURL& url,
|
| // Finally try the URL hostname, but only if there's no default specified in
|
| // |default_name|. Some schemes (e.g.: file:, about:, data:) do not have a
|
| // host name.
|
| - if (filename.empty() &&
|
| - default_name.empty() &&
|
| - url.is_valid() &&
|
| + if (filename.empty() && default_name.empty() && url.is_valid() &&
|
| !url.host().empty()) {
|
| // TODO(jungshik) : Decode a 'punycoded' IDN hostname. (bug 1264451)
|
| filename = url.host();
|
| @@ -450,8 +443,9 @@ base::string16 GetSuggestedFilename(const GURL& url,
|
| SanitizeGeneratedFileName(&result_str, replace_trailing);
|
| if (result_str.find_last_not_of(FILE_PATH_LITERAL("-_")) ==
|
| base::FilePath::StringType::npos) {
|
| - result_str = !default_name_str.empty() ? default_name_str :
|
| - base::FilePath::StringType(kFinalFallbackName);
|
| + result_str = !default_name_str.empty()
|
| + ? default_name_str
|
| + : base::FilePath::StringType(kFinalFallbackName);
|
| overwrite_extension = false;
|
| }
|
| file_util::ReplaceIllegalCharactersInPath(&result_str, '-');
|
|
|