diff --git a/Creek.FileRepository/Helpers/StringHelper.cs b/Creek.FileRepository/Helpers/StringHelper.cs index 82e235b..fa19330 100644 --- a/Creek.FileRepository/Helpers/StringHelper.cs +++ b/Creek.FileRepository/Helpers/StringHelper.cs @@ -4,8 +4,16 @@ using System.Text; namespace Creek.FileRepository.Helpers { + /// + /// A helper class for string methods. + /// internal class StringHelper { + /// + /// Checks if a filename contains invalid characters. + /// + /// The filename to be checked. + /// Returns true if the filename contains invalid characters. public static bool IsInvalidFileName(string filename) { char[] invalidCharacters = new char[] { '<', '>', ':', '\'', '/', '\\', '|', '?', '*' }; @@ -13,10 +21,15 @@ namespace Creek.FileRepository.Helpers return Array.Exists(invalidCharacters, character => filename.Contains(character.ToString())); } + /// + /// Sanitises a filename containing invalid characters. + /// + /// The filename to sanitise. + /// Returns the sanitised filename. internal static string MakeValidFileName(string originalFileName) { char[] invalids = System.IO.Path.GetInvalidFileNameChars(); - string validFileName = String.Join("_", originalFileName.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.'); + string validFileName = string.Join("_", originalFileName.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.'); // Additionally remove Windows characters explicitly, in case we're running on Linux (e.g. in Docker) but need to access the files in Windows string[] charsToRemove = new string[] { "<", ">", ":", "\"", "/", "\\", "|", "?", "*" }; @@ -26,6 +39,12 @@ namespace Creek.FileRepository.Helpers return validFileName; } + /// + /// Removes any characters in an array of strings from a string. + /// + /// The string array of characters to remove. + /// The string to modify. + /// Returns the modified string. internal static string RemoveCharsFromString(string[] charsToRemove, string str) { foreach (string c in charsToRemove)