| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/resource_provider/file_utils.h" | 5 #include "components/resource_provider/file_utils.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 "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 | 11 |
| 12 namespace resource_provider { | 12 namespace resource_provider { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 bool IsPathNameValid(const std::string& name) { | 15 bool IsPathNameValid(const std::string& name) { |
| 16 if (name.empty() || name == "." || name == "..") | 16 if (name.empty() || name == "." || name == "..") |
| 17 return false; | 17 return false; |
| 18 | 18 |
| 19 for (auto c : name) { | 19 for (auto c : name) { |
| 20 if (!IsAsciiAlpha(c) && !IsAsciiDigit(c) && c != '_' && c != '.') | 20 if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c) && |
| 21 c != '_' && c != '.') |
| 21 return false; | 22 return false; |
| 22 } | 23 } |
| 23 return true; | 24 return true; |
| 24 } | 25 } |
| 25 | 26 |
| 26 } // namespace | 27 } // namespace |
| 27 | 28 |
| 28 base::FilePath GetPathForApplicationUrl(const GURL& application_url) { | 29 base::FilePath GetPathForApplicationUrl(const GURL& application_url) { |
| 29 if (application_url.scheme() != "mojo") | 30 if (application_url.scheme() != "mojo") |
| 30 return base::FilePath(); | 31 return base::FilePath(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 base::FilePath result(app_path); | 66 base::FilePath result(app_path); |
| 66 for (const auto& path_component : path_components) { | 67 for (const auto& path_component : path_components) { |
| 67 if (!IsPathNameValid(path_component)) | 68 if (!IsPathNameValid(path_component)) |
| 68 return base::FilePath(); | 69 return base::FilePath(); |
| 69 result = result.AppendASCII(path_component); | 70 result = result.AppendASCII(path_component); |
| 70 } | 71 } |
| 71 return result; | 72 return result; |
| 72 } | 73 } |
| 73 | 74 |
| 74 } // namespace resource_provider | 75 } // namespace resource_provider |
| OLD | NEW |