summaryrefslogtreecommitdiffstats
path: root/chromium/net/base/filename_util_unsafe.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/base/filename_util_unsafe.cc')
-rw-r--r--chromium/net/base/filename_util_unsafe.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/chromium/net/base/filename_util_unsafe.cc b/chromium/net/base/filename_util_unsafe.cc
new file mode 100644
index 00000000000..12e80dcf32d
--- /dev/null
+++ b/chromium/net/base/filename_util_unsafe.cc
@@ -0,0 +1,51 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/filename_util_unsafe.h"
+
+#include "base/bind.h"
+#include "base/strings/string_util.h"
+#include "net/base/filename_util_internal.h"
+
+namespace {
+
+// Local ICU-independent implementation of filename sanitizing functions defined
+// in base/i18n/file_util_icu.h. Does not require ICU because on POSIX systems
+// all international characters are considered legal, so only control and
+// special characters have to be replaced.
+const base::FilePath::CharType illegal_characters[] =
+ FILE_PATH_LITERAL("\"*/:<>?\\\\|\001\002\003\004\005\006\007\010\011\012")
+ FILE_PATH_LITERAL("\013\014\015\016\017\020\021\022\023\024\025\025\027");
+
+void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name,
+ char replace_char) {
+ base::ReplaceChars(*file_name,
+ illegal_characters,
+ base::FilePath::StringType(1, replace_char),
+ file_name);
+}
+
+} // namespace
+
+namespace net {
+
+base::FilePath::StringType GenerateFileExtensionUnsafe(
+ const GURL& url,
+ const std::string& content_disposition,
+ const std::string& referrer_charset,
+ const std::string& suggested_name,
+ const std::string& mime_type,
+ const std::string& default_file_name) {
+ base::FilePath filepath =
+ GenerateFileNameImpl(url,
+ content_disposition,
+ referrer_charset,
+ suggested_name,
+ mime_type,
+ default_file_name,
+ base::Bind(&ReplaceIllegalCharactersInPath));
+ return filepath.Extension();
+}
+
+} // namespace net