The separator indicating the root directory was being incorrectly
removed, resulting in a path denoting the current directory.
path += DIRSEP;
path += comp;
}
- else if(separators.empty())
+ else if(start==0)
+ {
+ /* Removing the last component of a relative path results in the
+ current directory */
path = ".";
+ }
+ else if(start==1)
+ {
+ /* Removing the last component of an absolute path results in the
+ root directory */
+ path.erase(start, string::npos);
+ }
else
{
- // Otherwise, erase the last component
+ // Otherwise, erase the last component and its separator
path.erase(separators.back(), string::npos);
separators.pop_back();
}
EXPECT_EQUAL(path.str(), "./foo");
path = "foo/..";
EXPECT_EQUAL(path.str(), ".");
+ path = "/foo/..";
+ EXPECT_EQUAL(path.str(), "/");
path = "//foo";
EXPECT_EQUAL(path.str(), "/foo");
path = "/..";