From 73be5a52f9998ac019551afc071a6f690cd39073 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Thu, 2 Sep 2021 20:36:14 +0100 Subject: [PATCH] refactor(*): Use more human readable regex for determining if there are any invalid characters in a string --- Creek.FileRepository/Helpers/StringHelper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Creek.FileRepository/Helpers/StringHelper.cs b/Creek.FileRepository/Helpers/StringHelper.cs index 81e865b..974247f 100644 --- a/Creek.FileRepository/Helpers/StringHelper.cs +++ b/Creek.FileRepository/Helpers/StringHelper.cs @@ -17,9 +17,9 @@ namespace Creek.FileRepository.Helpers /// Returns true if the filename contains invalid characters. 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); } ///