cleaned up path validation logic.

pull/4/head
kay.one 11 years ago
parent bf415563d4
commit 9e08dffa58

@ -46,29 +46,26 @@ namespace NzbDrone.Common
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), StringComparison.InvariantCultureIgnoreCase); return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), StringComparison.InvariantCultureIgnoreCase);
} }
private static readonly Regex WindowsInvalidPathRegex = new Regex(@"[/*<>""|]", RegexOptions.Compiled); private static readonly Regex WindowsPathWithDriveRegex = new Regex(@"^[a-zA-Z]:\\", RegexOptions.Compiled);
private static readonly Regex WindowsPathRegex = new Regex(@"^[a-zA-Z]:\\", RegexOptions.Compiled);
public static bool IsPathValid(this string path) public static bool IsPathValid(this string path)
{ {
if (OsInfo.IsLinux && !path.StartsWith(Path.DirectorySeparatorChar.ToString())) if (path.ContainsInvalidPathChars())
{ {
return false; return false;
} }
if (WindowsInvalidPathRegex.IsMatch(path))
if (OsInfo.IsLinux)
{ {
return false; return path.StartsWith(Path.DirectorySeparatorChar.ToString());
} }
//Network path if (path.StartsWith("\\") || WindowsPathWithDriveRegex.IsMatch(path))
if (path.StartsWith(Path.DirectorySeparatorChar.ToString())) return true;
if (!WindowsPathRegex.IsMatch(path))
{ {
return false; return true;
} }
return true; return false;
} }

Loading…
Cancel
Save