Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: base/files/file_path.cc

Issue 1469153006: Treat '...' as a non-parent path component outside of Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DLOG(WARNING) Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/files/file_path_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 FilePath new_path(path_); 555 FilePath new_path(path_);
556 new_path.StripTrailingSeparatorsInternal(); 556 new_path.StripTrailingSeparatorsInternal();
557 557
558 return new_path; 558 return new_path;
559 } 559 }
560 560
561 bool FilePath::ReferencesParent() const { 561 bool FilePath::ReferencesParent() const {
562 std::vector<StringType> components; 562 std::vector<StringType> components;
563 GetComponents(&components); 563 GetComponents(&components);
564 564
565 std::vector<StringType>::const_iterator it = components.begin(); 565 for (const StringType& component : components) {
566 for (; it != components.end(); ++it) { 566 #if defined(OS_WIN)
567 const StringType& component = *it;
568 // Windows has odd, undocumented behavior with path components containing 567 // Windows has odd, undocumented behavior with path components containing
569 // only whitespace and . characters. So, if all we see is . and 568 // only whitespace and . characters. So, if all we see is . and
570 // whitespace, then we treat any .. sequence as referencing parent. 569 // whitespace, then we treat any .. sequence as referencing parent.
571 // For simplicity we enforce this on all platforms.
572 if (component.find_first_not_of(FILE_PATH_LITERAL(". \n\r\t")) == 570 if (component.find_first_not_of(FILE_PATH_LITERAL(". \n\r\t")) ==
573 std::string::npos && 571 std::string::npos &&
574 component.find(kParentDirectory) != std::string::npos) { 572 component.find(kParentDirectory) != std::string::npos) {
573 // Add a debug-only warning so Windows-specific bot failures are easier to
574 // diagnose.
575 DLOG_IF(WARNING, component != kParentDirectory)
576 << "Rejecting Windows-specific path component.";
575 return true; 577 return true;
576 } 578 }
579 #else
580 if (component == kParentDirectory)
581 return true;
582 #endif
577 } 583 }
578 return false; 584 return false;
579 } 585 }
580 586
581 #if defined(OS_POSIX) 587 #if defined(OS_POSIX)
582 // See file_path.h for a discussion of the encoding of paths on POSIX 588 // See file_path.h for a discussion of the encoding of paths on POSIX
583 // platforms. These encoding conversion functions are not quite correct. 589 // platforms. These encoding conversion functions are not quite correct.
584 590
585 string16 FilePath::LossyDisplayName() const { 591 string16 FilePath::LossyDisplayName() const {
586 return WideToUTF16(SysNativeMBToWide(path_)); 592 return WideToUTF16(SysNativeMBToWide(path_));
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 #endif 1318 #endif
1313 } 1319 }
1314 1320
1315 #if defined(OS_ANDROID) 1321 #if defined(OS_ANDROID)
1316 bool FilePath::IsContentUri() const { 1322 bool FilePath::IsContentUri() const {
1317 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII); 1323 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII);
1318 } 1324 }
1319 #endif 1325 #endif
1320 1326
1321 } // namespace base 1327 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/files/file_path_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698