refactor(*): Use more human readable regex for determining if there are any invalid characters in a string

This commit is contained in:
Josh Creek
2021-09-02 20:36:14 +01:00
parent 7cf5abd3ec
commit 73be5a52f9
+3 -3
View File
@@ -17,9 +17,9 @@ namespace Creek.FileRepository.Helpers
/// <returns>Returns true if the filename contains invalid characters.</returns>
public static bool IsInvalidFileName(this string filename)
{
char[] invalidCharacters = new char[] { '<', '>', ':', '\'', '/', '\\', '|', '?', '*' };
return Array.Exists(invalidCharacters, character => filename.Contains(character.ToString()));
// Check for Windows characters explicitly to ensure the filename is valid for Linux and Windows
Regex regex = new Regex(@"[<>:'\/\\|\?\*]");
return regex.IsMatch(filename);
}
/// <summary>