VirtualFileSystem: Fix false positives in YAMLVFSWriter::containedIn

Checking if a path starts with another path isn't sufficient for
determining if one is contained within the heirarchy of the other.
We need to ensure that the substring ends at a directory boundary.

llvm-svn: 209250
This commit is contained in:
Justin Bogner
2014-05-20 22:12:58 +00:00
parent 38ff567743
commit 1c078f2b1f
2 changed files with 61 additions and 1 deletions

View File

@@ -928,7 +928,16 @@ YAMLVFSWriter::printContents(llvm::raw_ostream &OS, ArrayRef<MapEntry> Entries,
}
bool YAMLVFSWriter::containedIn(StringRef Parent, StringRef Path) {
return Path.startswith(Parent);
using namespace llvm::sys;
// Compare each path component.
auto IParent = path::begin(Parent), EParent = path::end(Parent);
for (auto IChild = path::begin(Path), EChild = path::end(Path);
IParent != EParent && IChild != EChild; ++IParent, ++IChild) {
if (*IParent != *IChild)
return false;
}
// Have we exhausted the parent path?
return IParent == EParent;
}
StringRef YAMLVFSWriter::containedPart(StringRef Parent, StringRef Path) {