From d89e5a2e687efcf425211c9f7813834ead79a9ad Mon Sep 17 00:00:00 2001 From: PopSlime Date: Thu, 17 Nov 2022 12:00:33 +0800 Subject: [PATCH] Trims trailing spaces and dots when escaping file name instead of replacing them. --- Assets/Cryville/Common/StringUtils.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Assets/Cryville/Common/StringUtils.cs b/Assets/Cryville/Common/StringUtils.cs index b230bc8..cbff5fe 100644 --- a/Assets/Cryville/Common/StringUtils.cs +++ b/Assets/Cryville/Common/StringUtils.cs @@ -40,7 +40,9 @@ namespace Cryville.Common { /// The file name excluding the extension. /// The escaped file name. public static string EscapeFileName(string name) { - return Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}\.\s]", "_"); + var result = Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}]", "_").TrimEnd(' ', '.'); + if (result.Length == 0) return "_"; + return result; } } }