diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 8ffbb185ac0..6871b21c953 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -49,7 +49,6 @@ namespace { // * empty (in this case we return an empty string) // * either C: or {//,\\}net. // * {/,\} - // * {.,..} // * {file,directory}name if (path.empty()) @@ -76,12 +75,6 @@ namespace { if (is_separator(path[0])) return path.substr(0, 1); - if (path.startswith("..")) - return path.substr(0, 2); - - if (path[0] == '.') - return path.substr(0, 1); - // * {file,directory}name size_t end = path.find_first_of(separators); return path.substr(0, end); diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 00af989f485..479812c1eaa 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -168,6 +168,26 @@ TEST(Support, RelativePathIterator) { } } +TEST(Support, RelativePathDotIterator) { + SmallString<64> Path(StringRef(".c/.d/../.")); + typedef SmallVector PathComponents; + PathComponents ExpectedPathComponents; + PathComponents ActualPathComponents; + + StringRef(Path).split(ExpectedPathComponents, "/"); + + for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; + ++I) { + ActualPathComponents.push_back(*I); + } + + ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); + + for (size_t i = 0; i Path(StringRef("/c/d/e/foo.txt")); typedef SmallVector PathComponents; @@ -191,6 +211,29 @@ TEST(Support, AbsolutePathIterator) { } } +TEST(Support, AbsolutePathDotIterator) { + SmallString<64> Path(StringRef("/.c/.d/../.")); + typedef SmallVector PathComponents; + PathComponents ExpectedPathComponents; + PathComponents ActualPathComponents; + + StringRef(Path).split(ExpectedPathComponents, "/"); + + // The root path will also be a component when iterating + ExpectedPathComponents[0] = "/"; + + for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; + ++I) { + ActualPathComponents.push_back(*I); + } + + ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); + + for (size_t i = 0; i Path(StringRef("c:\\c\\e\\foo.txt"));