1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/base/filename_util_unsafe.h"
8 #include "base/strings/string_util.h"
9 #include "net/base/filename_util_internal.h"
13 // Local ICU-independent implementation of filename sanitizing functions defined
14 // in base/i18n/file_util_icu.h. Does not require ICU because on POSIX systems
15 // all international characters are considered legal, so only control and
16 // special characters have to be replaced.
17 const base::FilePath::CharType illegal_characters
[] =
18 FILE_PATH_LITERAL("\"*/:<>?\\\\|\001\002\003\004\005\006\007\010\011\012")
19 FILE_PATH_LITERAL("\013\014\015\016\017\020\021\022\023\024\025\025\027");
21 void ReplaceIllegalCharactersInPath(base::FilePath::StringType
* file_name
,
23 base::ReplaceChars(*file_name
,
25 base::FilePath::StringType(1, replace_char
),
33 base::FilePath::StringType
GenerateFileExtensionUnsafe(
35 const std::string
& content_disposition
,
36 const std::string
& referrer_charset
,
37 const std::string
& suggested_name
,
38 const std::string
& mime_type
,
39 const std::string
& default_file_name
) {
40 base::FilePath filepath
=
41 GenerateFileNameImpl(url
,
47 base::Bind(&ReplaceIllegalCharactersInPath
));
48 return filepath
.Extension();