| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/util/filename_util.h" | 5 #include "mojo/util/filename_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 url_string.push_back(base::FilePath::kSeparators[0]); | 31 url_string.push_back(base::FilePath::kSeparators[0]); |
| 32 } | 32 } |
| 33 url_string.append(path.value()); | 33 url_string.append(path.value()); |
| 34 | 34 |
| 35 // Now do replacement of some characters. Since we assume the input is a | 35 // Now do replacement of some characters. Since we assume the input is a |
| 36 // literal filename, anything the URL parser might consider special should | 36 // literal filename, anything the URL parser might consider special should |
| 37 // be escaped here. | 37 // be escaped here. |
| 38 | 38 |
| 39 // This must be the first substitution since others will introduce percents as | 39 // This must be the first substitution since others will introduce percents as |
| 40 // the escape character | 40 // the escape character |
| 41 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("%"), | 41 base::ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("%"), |
| 42 FILE_PATH_LITERAL("%25")); | 42 FILE_PATH_LITERAL("%25")); |
| 43 | 43 |
| 44 // A semicolon is supposed to be some kind of separator according to RFC 2396. | 44 // A semicolon is supposed to be some kind of separator according to RFC 2396. |
| 45 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL(";"), | 45 base::ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL(";"), |
| 46 FILE_PATH_LITERAL("%3B")); | 46 FILE_PATH_LITERAL("%3B")); |
| 47 | 47 |
| 48 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("#"), | 48 base::ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("#"), |
| 49 FILE_PATH_LITERAL("%23")); | 49 FILE_PATH_LITERAL("%23")); |
| 50 | 50 |
| 51 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("?"), | 51 base::ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("?"), |
| 52 FILE_PATH_LITERAL("%3F")); | 52 FILE_PATH_LITERAL("%3F")); |
| 53 | 53 |
| 54 #if defined(OS_POSIX) | 54 #if defined(OS_POSIX) |
| 55 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("\\"), | 55 base::ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("\\"), |
| 56 FILE_PATH_LITERAL("%5C")); | 56 FILE_PATH_LITERAL("%5C")); |
| 57 #endif | 57 #endif |
| 58 | 58 |
| 59 return GURL(url_string); | 59 return GURL(url_string); |
| 60 } | 60 } |
| 61 | 61 |
| 62 GURL AddTrailingSlashIfNeeded(const GURL& url) { | 62 GURL AddTrailingSlashIfNeeded(const GURL& url) { |
| 63 if (!url.has_path() || *url.path().rbegin() == '/') | 63 if (!url.has_path() || *url.path().rbegin() == '/') |
| 64 return url; | 64 return url; |
| 65 | 65 |
| 66 std::string path(url.path() + '/'); | 66 std::string path(url.path() + '/'); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 79 base::TrimString(decoded_path, L"/", &decoded_path); | 79 base::TrimString(decoded_path, L"/", &decoded_path); |
| 80 base::FilePath path(decoded_path); | 80 base::FilePath path(decoded_path); |
| 81 #else | 81 #else |
| 82 base::FilePath path(base::UTF16ToUTF8(decoded_path)); | 82 base::FilePath path(base::UTF16ToUTF8(decoded_path)); |
| 83 #endif | 83 #endif |
| 84 return path; | 84 return path; |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace util | 87 } // namespace util |
| 88 } // namespace mojo | 88 } // namespace mojo |
| OLD | NEW |