Fix handling of consecutive slashes in FileSpec::GetNormalizedPath()

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
This commit is contained in:
Pavel Labath 2016-11-30 16:08:45 +00:00
parent 5d92bc5bd9
commit e6e7e6c348
2 changed files with 5 additions and 1 deletions

View 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;

View 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"},
{"/", "/"},
{"//", "//"},