static internal bool IsValid(string configPath) {
if (String.IsNullOrEmpty(configPath)) {
return false;
}
int start = -1;
for (int examine = 0; examine <= configPath.Length; examine++) {
char ch;
if (examine < configPath.Length) {
ch = configPath[examine];
}
else {
ch = SeparatorChar;
}
// backslash disallowed
if (ch == '\\') {
return false;
}
if (ch == SeparatorChar) {
// double slash disallowed
// note this check also purposefully catches starting and ending slash
if (examine == start + 1) {
return false;
}
// "." disallowed
if (examine == start + 2 && configPath[start + 1] == '.') {
return false;
}
// ".." disallowed
if (examine == start + 3 && configPath[start + 1] == '.' && configPath[start + 2] == '.') {
return false;
}
start = examine;
}
}
return true;
}