File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -48,10 +48,15 @@ std::pair<absl::string_view, absl::string_view> SplitPath(
4848// Collapses duplicate "/"s, resolve ".." and "." path elements, removes
4949// trailing "/".
5050//
51- // NOTE: This respects relative vs. absolute paths, but does not
52- // invoke any system calls in order to resolve relative paths to the actual
53- // working directory. That is, this is purely a string manipulation, completely
54- // independent of process state.
51+ // This is purely a string manipulation and does not invoke any system calls in
52+ // order to resolve relative paths to the actual working directory.
53+ //
54+ // For absolute paths, this is equivalent to the following:
55+ // /path/to/./foo/../bar/../baz/ -> /path/to/bar/baz
56+ //
57+ // For relative paths, this is equivalent to the following:
58+ // ./path/to/./foo/../bar/../baz/ -> path/to/bar/baz
59+ // ../path/to/./foo/../bar/../baz/ -> ../path/to/bar/baz
5560std::string CleanPath (absl::string_view path);
5661
5762} // namespace sapi::file
Original file line number Diff line number Diff line change @@ -96,6 +96,12 @@ TEST(PathTest, CleanPath) {
9696 EXPECT_THAT (file::CleanPath (" ../../a/b/../c" ), StrEq (" ../../a/c" ));
9797 EXPECT_THAT (file::CleanPath (" ../../a/b/../c/../.." ), StrEq (" ../.." ));
9898 EXPECT_THAT (file::CleanPath (" foo/../../../bar" ), StrEq (" ../../bar" ));
99+ EXPECT_THAT (file::CleanPath (" /path/to/./foo/../bar/../baz/" ),
100+ StrEq (" /path/to/baz" ));
101+ EXPECT_THAT (file::CleanPath (" ./path/to/./foo/../bar/../baz/" ),
102+ StrEq (" path/to/baz" ));
103+ EXPECT_THAT (file::CleanPath (" ../path/to/./foo/../bar/../baz/" ),
104+ StrEq (" ../path/to/baz" ));
99105}
100106
101107} // namespace
You can’t perform that action at this time.
0 commit comments