Fixes paths regex checks not recognizing [ and ]

This commit is contained in:
BinaryAlley committed 2024-10-06 18:05:03 +03:00
1 parent 65ab0c99c3
commit 9e290d7f09
2 files changed
+4 -4

No files matched your search

@@ -50,8 +50,8 @@ public class UnixPathStrategy : IUnixPathStrategy
// check for relative paths
if (path.Path.StartsWith("./") || path.Path.StartsWith("../"))
return false;
string pathPattern = @"^\/([\w\-\.\~!$&'()*+,;=:@ ]+(\/[\w\-\.\~!$&'()*+,;=:@ ]+)*)?\/?$";
return Regex.IsMatch(path.Path, pathPattern);
const string PATH_PATTERN = @"^\/([\w\-\.\~!$&'()*+,;=:@\[\] ]+(\/[\w\-\.\~!$&'()*+,;=:@\[\] ]+)*)?\/?$";
return Regex.IsMatch(path.Path, PATH_PATTERN);
}
/// <summary>
@@ -49,8 +49,8 @@ public class WindowsPathStrategy : IWindowsPathStrategy
return false;
// regular expression to match valid absolute paths
// 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()._-]*\\?$";
return Regex.IsMatch(path.Path, pathPattern);
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, PATH_PATTERN);
}
/// <summary>