mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-19 21:44:30 -04:00
added path validation to add series/ recent folders.
This commit is contained in:
@@ -95,8 +95,7 @@ namespace NzbDrone.Common.EnsureThat
|
||||
return param;
|
||||
}
|
||||
|
||||
private static readonly Regex windowsInvalidPathRegex = new Regex(@"[/*<>""|]", RegexOptions.Compiled);
|
||||
private static readonly Regex windowsPathRegex = new Regex(@"^[a-zA-Z]:\\", RegexOptions.Compiled);
|
||||
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public static Param<string> IsValidPath(this Param<string> param)
|
||||
@@ -104,31 +103,14 @@ namespace NzbDrone.Common.EnsureThat
|
||||
if (string.IsNullOrWhiteSpace(param.Value))
|
||||
throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotNullOrWhiteSpace);
|
||||
|
||||
if (param.Value.IsPathValid()) return param;
|
||||
|
||||
if (OsInfo.IsLinux)
|
||||
{
|
||||
if (!param.Value.StartsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}] is not a valid *nix path. paths must start with /", param.Value));
|
||||
}
|
||||
throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}] is not a valid *nix path. paths must start with /", param.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (windowsInvalidPathRegex.IsMatch(param.Value))
|
||||
{
|
||||
throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}] is not a valid Windows path. It contains invalid characters", param.Value));
|
||||
}
|
||||
|
||||
//Network path
|
||||
if (param.Value.StartsWith(Path.DirectorySeparatorChar.ToString())) return param;
|
||||
|
||||
if (!windowsPathRegex.IsMatch(param.Value))
|
||||
{
|
||||
throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}] is not a valid Windows path. paths must be a full path eg. C:\\Windows", param.Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return param;
|
||||
|
||||
throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}] is not a valid Windows path. paths must be a full path eg. C:\\Windows", param.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
@@ -45,6 +46,32 @@ namespace NzbDrone.Common
|
||||
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);
|
||||
|
||||
public static bool IsPathValid(this string path)
|
||||
{
|
||||
if (OsInfo.IsLinux && !path.StartsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (WindowsInvalidPathRegex.IsMatch(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Network path
|
||||
if (path.StartsWith(Path.DirectorySeparatorChar.ToString())) return true;
|
||||
|
||||
if (!WindowsPathRegex.IsMatch(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static bool ContainsInvalidPathChars(this string text)
|
||||
{
|
||||
return text.IndexOfAny(Path.GetInvalidPathChars()) >= 0;
|
||||
|
||||
Reference in New Issue
Block a user