Fix handling of consecutive slashes in FileSpec::GetNormalizedPath()
authorPavel Labath <labath@google.com>
Wed, 30 Nov 2016 16:08:45 +0000 (16:08 +0000)
committerPavel Labath <labath@google.com>
Wed, 30 Nov 2016 16:08:45 +0000 (16:08 +0000)
The core of the function was actually handling them correctly. However, the
early exit was being too optimistic and did not give the function a chance to
fire if the path did not contain dots as well.

Fix that and add a couple of unit tests.

llvm-svn: 288247

lldb/source/Host/common/FileSpec.cpp
lldb/unittests/Host/FileSpecTest.cpp

index d958d8c..9287336 100644 (file)
@@ -544,7 +544,8 @@ bool FileSpec::Equal(const FileSpec &a, const FileSpec &b, bool full,
 FileSpec FileSpec::GetNormalizedPath() const {
   // Fast path. Do nothing if the path is not interesting.
   if (!m_directory.GetStringRef().contains(".") &&
-      (m_filename.GetStringRef() != ".." && m_filename.GetStringRef() != "."))
+      !m_directory.GetStringRef().contains("//") &&
+      m_filename.GetStringRef() != ".." && m_filename.GetStringRef() != ".")
     return *this;
 
   llvm::SmallString<64> path, result;
index 843dcb8..338515d 100644 (file)
@@ -206,6 +206,9 @@ TEST(FileSpecTest, GetNormalizedPath) {
       {"/foo/./bar", "/foo/bar"},
       {"/foo/..", "/"},
       {"/foo/.", "/foo"},
+      {"/foo//bar", "/foo/bar"},
+      {"/foo//bar/baz", "/foo/bar/baz"},
+      {"/foo//bar/./baz", "/foo/bar/baz"},
       {"/./foo", "/foo"},
       {"/", "/"},
       {"//", "//"},