Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 } | 553 } |
| 554 | 554 |
| 555 FilePath FilePath::StripTrailingSeparators() const { | 555 FilePath FilePath::StripTrailingSeparators() const { |
| 556 FilePath new_path(path_); | 556 FilePath new_path(path_); |
| 557 new_path.StripTrailingSeparatorsInternal(); | 557 new_path.StripTrailingSeparatorsInternal(); |
| 558 | 558 |
| 559 return new_path; | 559 return new_path; |
| 560 } | 560 } |
| 561 | 561 |
| 562 bool FilePath::ReferencesParent() const { | 562 bool FilePath::ReferencesParent() const { |
| 563 if (path_.find(kParentDirectory) == StringType::npos) { | |
| 564 // GetComponents is quite expensive, so avoid calling it in the majority | |
| 565 // of cases where there isn't a kParentDirectory anywhere in the path. | |
| 566 return false; | |
| 567 } | |
| 568 | |
| 563 std::vector<StringType> components; | 569 std::vector<StringType> components; |
|
danakj
2016/11/11 19:17:40
This is great!
Question tho: We should probably u
jkarlin
2016/11/11 19:38:24
Are you suggesting that GetComponents should take
danakj
2016/11/11 19:57:27
Ah ok, it's not trivial at all np. This LGTM!
| |
| 564 GetComponents(&components); | 570 GetComponents(&components); |
| 565 | 571 |
| 566 std::vector<StringType>::const_iterator it = components.begin(); | 572 std::vector<StringType>::const_iterator it = components.begin(); |
| 567 for (; it != components.end(); ++it) { | 573 for (; it != components.end(); ++it) { |
| 568 const StringType& component = *it; | 574 const StringType& component = *it; |
| 569 // Windows has odd, undocumented behavior with path components containing | 575 // Windows has odd, undocumented behavior with path components containing |
| 570 // only whitespace and . characters. So, if all we see is . and | 576 // only whitespace and . characters. So, if all we see is . and |
| 571 // whitespace, then we treat any .. sequence as referencing parent. | 577 // whitespace, then we treat any .. sequence as referencing parent. |
| 572 // For simplicity we enforce this on all platforms. | 578 // For simplicity we enforce this on all platforms. |
| 573 if (component.find_first_not_of(FILE_PATH_LITERAL(". \n\r\t")) == | 579 if (component.find_first_not_of(FILE_PATH_LITERAL(". \n\r\t")) == |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1327 #endif | 1333 #endif |
| 1328 } | 1334 } |
| 1329 | 1335 |
| 1330 #if defined(OS_ANDROID) | 1336 #if defined(OS_ANDROID) |
| 1331 bool FilePath::IsContentUri() const { | 1337 bool FilePath::IsContentUri() const { |
| 1332 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII); | 1338 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII); |
| 1333 } | 1339 } |
| 1334 #endif | 1340 #endif |
| 1335 | 1341 |
| 1336 } // namespace base | 1342 } // namespace base |
| OLD | NEW |