Fix and improve win32 path validation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19545 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jeff Cohen 2005-01-14 04:09:39 +00:00
parent 62582720e6
commit 3bbbcc113b

View File

@ -55,17 +55,29 @@ Path::isValid() const {
!= std::string::npos) != std::string::npos)
return false; return false;
// A file or directory name may not end in a period. // Check each component for legality.
if (path[len-1] == '.') for (pos = 0; pos < len; ++pos) {
return false; // A component may not end in a space.
if (len >= 2 && path[len-2] == '.' && path[len-1] == '/') if (path[pos] == ' ') {
return false; if (path[pos+1] == '/' || path[pos+1] == '\0')
return false;
}
// A file or directory name may not end in a space. // A component may not end in a period.
if (path[len-1] == ' ') if (path[pos] == '.') {
return false; if (path[pos+1] == '/' || path[pos+1] == '\0') {
if (len >= 2 && path[len-2] == ' ' && path[len-1] == '/') // Unless it is the pseudo-directory "."...
return false; if (pos == 0 || path[pos-1] == '/' || path[pos-1] == ':')
return true;
// or "..".
if (pos > 0 && path[pos-1] == '.') {
if (pos == 1 || path[pos-2] == '/' || path[pos-2] == ':')
return true;
}
return false;
}
}
}
return true; return true;
} }