From 9e08dffa58c4a8b39bca97a3a6b31e0e632b18ec Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 31 Aug 2013 13:43:35 -0700 Subject: [PATCH] cleaned up path validation logic. --- NzbDrone.Common/PathExtensions.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/NzbDrone.Common/PathExtensions.cs b/NzbDrone.Common/PathExtensions.cs index 2cdd5dd44..68938c55a 100644 --- a/NzbDrone.Common/PathExtensions.cs +++ b/NzbDrone.Common/PathExtensions.cs @@ -46,29 +46,26 @@ 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); + 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())) + if (path.ContainsInvalidPathChars()) { return false; } - if (WindowsInvalidPathRegex.IsMatch(path)) + + if (OsInfo.IsLinux) { - return false; + return path.StartsWith(Path.DirectorySeparatorChar.ToString()); } - //Network path - if (path.StartsWith(Path.DirectorySeparatorChar.ToString())) return true; - - if (!WindowsPathRegex.IsMatch(path)) + if (path.StartsWith("\\") || WindowsPathWithDriveRegex.IsMatch(path)) { - return false; + return true; } - return true; + return false; }