cleaned up path validation logic.
This commit is contained in:
parent
bf415563d4
commit
9e08dffa58
|
@ -46,31 +46,28 @@ 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;
|
|
||||||
}
|
|
||||||
if (WindowsInvalidPathRegex.IsMatch(path))
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Network path
|
if (OsInfo.IsLinux)
|
||||||
if (path.StartsWith(Path.DirectorySeparatorChar.ToString())) return true;
|
|
||||||
|
|
||||||
if (!WindowsPathRegex.IsMatch(path))
|
|
||||||
{
|
{
|
||||||
return false;
|
return path.StartsWith(Path.DirectorySeparatorChar.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path.StartsWith("\\") || WindowsPathWithDriveRegex.IsMatch(path))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static bool ContainsInvalidPathChars(this string text)
|
public static bool ContainsInvalidPathChars(this string text)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue