Merge pull request #17 from BinaryAlley/bugfix/fix-file-system-path-check-regex

Fixes paths regex checks not recognizing [ and ]
This commit is contained in:
BinaryAlley authored and GitHub committed 2024-10-06 18:06:57 +03:00
commit 7321dc5dab
2 files changed
+4 -4

No files matched your search

@@ -50,8 +50,8 @@ public class UnixPathStrategy : IUnixPathStrategy
// check for relative paths // check for relative paths
if (path.Path.StartsWith("./") || path.Path.StartsWith("../")) if (path.Path.StartsWith("./") || path.Path.StartsWith("../"))
return false; return false;
string pathPattern = @"^\/([\w\-\.\~!$&'()*+,;=:@ ]+(\/[\w\-\.\~!$&'()*+,;=:@ ]+)*)?\/?$"; const string PATH_PATTERN = @"^\/([\w\-\.\~!$&'()*+,;=:@\[\] ]+(\/[\w\-\.\~!$&'()*+,;=:@\[\] ]+)*)?\/?$";
return Regex.IsMatch(path.Path, pathPattern); return Regex.IsMatch(path.Path, PATH_PATTERN);
} }
/// <summary> /// <summary>
@@ -49,8 +49,8 @@ public class WindowsPathStrategy : IWindowsPathStrategy
return false; return false;
// regular expression to match valid absolute paths // regular expression to match valid absolute paths
// this allows drive letters (e.g., C:\) and UNC paths (e.g., \\server\share) // this allows drive letters (e.g., C:\) and UNC paths (e.g., \\server\share)
string pathPattern = @"^(?:[a-zA-Z]:\\|\\\\[a-zA-Z0-9\s()._-]+\\[a-zA-Z0-9\s()._-]+)(?:[a-zA-Z0-9\s()._-]+\\)*[a-zA-Z0-9\s()._-]*\\?$"; const string PATH_PATTERN = @"^(?:[a-zA-Z]:\\|\\\\[a-zA-Z0-9\s()._\[\]-]+\\[a-zA-Z0-9\s()._\[\]-]+)(?:[a-zA-Z0-9\s()._\[\]-]+\\)*[a-zA-Z0-9\s()._\[\]-]*\\?$";
return Regex.IsMatch(path.Path, pathPattern); return Regex.IsMatch(path.Path, PATH_PATTERN);
} }
/// <summary> /// <summary>