diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-18 07:52:50 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-18 07:52:50 +0000 |
commit | 820dbd12fa9c8e1fd25f1e8c0aa33a00e2e7e2f3 (patch) | |
tree | 3e670ed454575fd4e1e640697957a4db8615372a /webkit | |
parent | cbc3b9892ef98b6b4b613b5016cfb2adc55195fe (diff) | |
download | chromium_src-820dbd12fa9c8e1fd25f1e8c0aa33a00e2e7e2f3.zip chromium_src-820dbd12fa9c8e1fd25f1e8c0aa33a00e2e7e2f3.tar.gz chromium_src-820dbd12fa9c8e1fd25f1e8c0aa33a00e2e7e2f3.tar.bz2 |
Retry: 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).
Original review: https://codereview.chromium.org/12253006/
BUG=none
TEST=FileSystemUtilTest.VirtualPathGetComponents
TBR=ericu, tzik (original reviewers)
Review URL: https://codereview.chromium.org/12218142
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/fileapi/file_system_util.cc | 26 | ||||
-rw-r--r-- | webkit/fileapi/file_system_util.h | 11 | ||||
-rw-r--r-- | webkit/fileapi/file_system_util_unittest.cc | 8 |
3 files changed, 26 insertions, 19 deletions
diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc index 0960d0cb..1447c99 100644 --- a/webkit/fileapi/file_system_util.cc +++ b/webkit/fileapi/file_system_util.cc @@ -49,7 +49,10 @@ base::FilePath VirtualPath::BaseName(const base::FilePath& virtual_path) { } void VirtualPath::GetComponents( - const base::FilePath& path, std::vector<base::FilePath::StringType>* components) { + const base::FilePath& path, + std::vector<base::FilePath::StringType>* components) { + typedef base::FilePath::StringType StringType; + DCHECK(components); if (!components) return; @@ -57,20 +60,15 @@ void VirtualPath::GetComponents( if (path.value().empty()) return; - std::vector<base::FilePath::StringType> 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(); + 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; } - - *components = - std::vector<base::FilePath::StringType>(ret_val.rbegin(), ret_val.rend()); } base::FilePath::StringType VirtualPath::GetNormalizedFilePath( diff --git a/webkit/fileapi/file_system_util.h b/webkit/fileapi/file_system_util.h index 60ac4c0..f77cbe0 100644 --- a/webkit/fileapi/file_system_util.h +++ b/webkit/fileapi/file_system_util.h @@ -36,11 +36,12 @@ 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 '.' or '..' 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 '..' components. + static void GetComponents( + const base::FilePath& path, std::vector<base::FilePath::StringType>* 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 1b23d34..40849e5 100644 --- a/webkit/fileapi/file_system_util_unittest.cc +++ b/webkit/fileapi/file_system_util_unittest.cc @@ -106,6 +106,14 @@ 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); |