mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-10 04:52:42 +01:00
cleaned up path validation logic.
This commit is contained in:
parent
bf415563d4
commit
9e08dffa58
@ -46,29 +46,26 @@ public static bool PathEquals(this string firstPath, string secondPath)
|
||||
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
private static readonly Regex WindowsInvalidPathRegex = new Regex(@"[/*<>""|]", RegexOptions.Compiled);
|
||||
private static readonly Regex WindowsPathRegex = new Regex(@"^[a-zA-Z]:\\", RegexOptions.Compiled);
|
||||
private static readonly Regex WindowsPathWithDriveRegex = new Regex(@"^[a-zA-Z]:\\", RegexOptions.Compiled);
|
||||
|
||||
public static bool IsPathValid(this string path)
|
||||
{
|
||||
if (OsInfo.IsLinux && !path.StartsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (WindowsInvalidPathRegex.IsMatch(path))
|
||||
if (path.ContainsInvalidPathChars())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Network path
|
||||
if (path.StartsWith(Path.DirectorySeparatorChar.ToString())) return true;
|
||||
|
||||
if (!WindowsPathRegex.IsMatch(path))
|
||||
if (OsInfo.IsLinux)
|
||||
{
|
||||
return false;
|
||||
return path.StartsWith(Path.DirectorySeparatorChar.ToString());
|
||||
}
|
||||
|
||||
return true;
|
||||
if (path.StartsWith("\\") || WindowsPathWithDriveRegex.IsMatch(path))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user