From 36cb60808422968817bb1154fcb9aaeddb6a077e Mon Sep 17 00:00:00 2001 From: "atwilson@chromium.org" Date: Fri, 15 Feb 2013 15:36:09 +0000 Subject: Revert 182604 because it breaks fast/filesystem/op-restricted-chars.html The fast/filesystem/op-restricted-chars.html layout test started failing as of this CL. > Fix VirtualPath::GetComponents to handle drive letter string as usual path component > > Also fix the function comment as the existing code seems to handle the '.' component correctly (and so does the new code). > > BUG=none > TEST=FileSystemUtilTest.VirtualPathGetComponents > > Review URL: https://codereview.chromium.org/12253006 TBR=kinuko@chromium.org Review URL: https://codereview.chromium.org/12277003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182715 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/fileapi/file_system_util.cc | 26 ++++++++++++++------------ webkit/fileapi/file_system_util.h | 11 +++++------ webkit/fileapi/file_system_util_unittest.cc | 8 -------- 3 files changed, 19 insertions(+), 26 deletions(-) (limited to 'webkit') diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc index 79e2b76..24513d8 100644 --- a/webkit/fileapi/file_system_util.cc +++ b/webkit/fileapi/file_system_util.cc @@ -49,10 +49,7 @@ base::FilePath VirtualPath::BaseName(const base::FilePath& virtual_path) { } void VirtualPath::GetComponents( - const base::FilePath& path, - std::vector* components) { - typedef base::FilePath::StringType StringType; - + const base::FilePath& path, std::vector* components) { DCHECK(components); if (!components) return; @@ -60,15 +57,20 @@ void VirtualPath::GetComponents( if (path.value().empty()) return; - StringType::size_type begin = 0, end = 0; - while (begin < path.value().length() && end != StringType::npos) { - end = path.value().find_first_of(base::FilePath::kSeparators, begin); - StringType component = path.value().substr( - begin, end == StringType::npos ? StringType::npos : end - begin); - if (!component.empty() && component != base::FilePath::kCurrentDirectory) - components->push_back(component); - begin = end + 1; + std::vector ret_val; + base::FilePath current = path; + base::FilePath base; + + // Due to the way things are implemented, base::FilePath::DirName works here, + // whereas base::FilePath::BaseName doesn't. + while (current != current.DirName()) { + base = BaseName(current); + ret_val.push_back(base.value()); + current = current.DirName(); } + + *components = + std::vector(ret_val.rbegin(), ret_val.rend()); } FilePath::StringType VirtualPath::GetNormalizedFilePath(const FilePath& path) { diff --git a/webkit/fileapi/file_system_util.h b/webkit/fileapi/file_system_util.h index 351f094..ffefe57 100644 --- a/webkit/fileapi/file_system_util.h +++ b/webkit/fileapi/file_system_util.h @@ -36,12 +36,11 @@ class WEBKIT_STORAGE_EXPORT VirtualPath { // character. static base::FilePath BaseName(const base::FilePath& virtual_path); - // Likewise, use this instead of base::FilePath::GetComponents when - // operating on virtual paths. - // Note that this assumes very clean input, with no leading slash, and - // it will not evaluate '..' components. - static void GetComponents( - const base::FilePath& path, + // Likewise, use this instead of base::FilePath::GetComponents when operating on + // virtual paths. + // Note that this assumes very clean input, with no leading slash, and it will + // not evaluate '.' or '..' components. + static void GetComponents(const base::FilePath& path, std::vector* components); // Returns a path name ensuring that it begins with kRoot and all path diff --git a/webkit/fileapi/file_system_util_unittest.cc b/webkit/fileapi/file_system_util_unittest.cc index 6ffe873..3bf54fb 100644 --- a/webkit/fileapi/file_system_util_unittest.cc +++ b/webkit/fileapi/file_system_util_unittest.cc @@ -106,14 +106,6 @@ TEST_F(FileSystemUtilTest, VirtualPathGetComponents) { { FILE_PATH_LITERAL("/foo/bar"), 2, { FILE_PATH_LITERAL("foo"), FILE_PATH_LITERAL("bar") } }, - { FILE_PATH_LITERAL("c:/bar"), - 2, - { FILE_PATH_LITERAL("c:"), FILE_PATH_LITERAL("bar") } }, -#ifdef FILE_PATH_USES_WIN_SEPARATORS - { FILE_PATH_LITERAL("c:\\bar"), - 2, - { FILE_PATH_LITERAL("c:"), FILE_PATH_LITERAL("bar") } }, -#endif }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { base::FilePath input = base::FilePath(test_cases[i].path); -- cgit v1.1