From c571058817bfe9e516d513fbe1dde07413451ade Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Sat, 7 Jan 2023 12:57:58 -0600 Subject: [PATCH] Replace colons in titles with hyphens for file safety --- LANCommander.SDK/Extensions/StringExtensions.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/LANCommander.SDK/Extensions/StringExtensions.cs b/LANCommander.SDK/Extensions/StringExtensions.cs index 9771b96..ceb939c 100644 --- a/LANCommander.SDK/Extensions/StringExtensions.cs +++ b/LANCommander.SDK/Extensions/StringExtensions.cs @@ -7,9 +7,13 @@ namespace LANCommander.SDK.Extensions { public static string SanitizeFilename(this string filename, string replacement = "") { + var colonInTitle = new Regex(@"(\w)(: )(\w)"); var removeInvalidChars = new Regex($"[{Regex.Escape(new string(Path.GetInvalidFileNameChars()))}]", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.CultureInvariant); - return removeInvalidChars.Replace(filename, replacement); + filename = colonInTitle.Replace(filename, "$1 - $3"); + filename = removeInvalidChars.Replace(filename, replacement); + + return filename; } } }