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/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 return new_path; | 546 return new_path; |
547 } | 547 } |
548 | 548 |
549 bool FilePath::ReferencesParent() const { | 549 bool FilePath::ReferencesParent() const { |
550 std::vector<StringType> components; | 550 std::vector<StringType> components; |
551 GetComponents(&components); | 551 GetComponents(&components); |
552 | 552 |
553 std::vector<StringType>::const_iterator it = components.begin(); | 553 std::vector<StringType>::const_iterator it = components.begin(); |
554 for (; it != components.end(); ++it) { | 554 for (; it != components.end(); ++it) { |
555 const StringType& component = *it; | 555 const StringType& component = *it; |
556 // Windows has odd, undocumented behavior with path components containing | 556 if (component == kParentDirectory) |
557 // only whitespace and . characters. So, if all we see is . and | |
558 // whitespace, then we treat any .. sequence as referencing parent. | |
559 // For simplicity we enforce this on all platforms. | |
560 if (component.find_first_not_of(FILE_PATH_LITERAL(". \n\r\t")) == | |
561 std::string::npos && | |
562 component.find(kParentDirectory) != std::string::npos) { | |
563 return true; | 557 return true; |
564 } | |
565 } | 558 } |
566 return false; | 559 return false; |
567 } | 560 } |
568 | 561 |
569 #if defined(OS_POSIX) | 562 #if defined(OS_POSIX) |
570 // See file_path.h for a discussion of the encoding of paths on POSIX | 563 // See file_path.h for a discussion of the encoding of paths on POSIX |
571 // platforms. These encoding conversion functions are not quite correct. | 564 // platforms. These encoding conversion functions are not quite correct. |
572 | 565 |
573 string16 FilePath::LossyDisplayName() const { | 566 string16 FilePath::LossyDisplayName() const { |
574 return WideToUTF16(SysNativeMBToWide(path_)); | 567 return WideToUTF16(SysNativeMBToWide(path_)); |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 #else | 1269 #else |
1277 return *this; | 1270 return *this; |
1278 #endif | 1271 #endif |
1279 } | 1272 } |
1280 | 1273 |
1281 } // namespace base | 1274 } // namespace base |
1282 | 1275 |
1283 void PrintTo(const base::FilePath& path, std::ostream* out) { | 1276 void PrintTo(const base::FilePath& path, std::ostream* out) { |
1284 *out << path.value(); | 1277 *out << path.value(); |
1285 } | 1278 } |
OLD | NEW |