From 201948eac8e8173fc258d526913384388a65b3c7 Mon Sep 17 00:00:00 2001 From: Meloong Bot <110167337+HexDragon-Bot@users.noreply.github.com> Date: Sun, 11 Oct 2026 02:55:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E8=AE=A9=E8=B7=AF=E5=BE=84=E6=AF=94?= =?UTF-8?q?=E8=BE=83=E4=B8=8D=E5=8F=97=E5=BD=93=E5=89=8D=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/Utils/PathUtils.cs | 6 +++--- Tests/Utils/DirectoryUtilsTest.cs | 28 ++++++++++++++++++++++++++++ Tests/Utils/FileUtilsTest.cs | 27 +++++++++++++++++++++++++++ Tests/Utils/PathUtilsTest.cs | 25 +++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) diff --git a/Shared/Utils/PathUtils.cs b/Shared/Utils/PathUtils.cs index cb55478..7ae65b3 100644 --- a/Shared/Utils/PathUtils.cs +++ b/Shared/Utils/PathUtils.cs @@ -232,7 +232,7 @@ public static class PathUtils { return PathUtils.Compare(path1, path2) == 0; } /// - /// 比较两个路径,忽略大小写。 + /// 比较两个路径,忽略大小写,且不受当前语言设置影响。 /// null 与空字符串视为相同的空路径,空路径排在非空路径之前。 /// /// @@ -243,7 +243,7 @@ public static class PathUtils { public static int Compare(string? path1, string? path2) { if (string.IsNullOrEmpty(path1)) return string.IsNullOrEmpty(path2) ? 0 : -1; if (string.IsNullOrEmpty(path2)) return 1; - return string.Compare(PathUtils.ForCompare(path1!), PathUtils.ForCompare(path2!), true); + return string.Compare(PathUtils.ForCompare(path1!), PathUtils.ForCompare(path2!), StringComparison.OrdinalIgnoreCase); } /// @@ -265,7 +265,7 @@ public static class PathUtils { public static bool IsParentOf(string parentPath, string childPath) { parentPath = PathUtils.ForCompare(parentPath); childPath = PathUtils.ForCompare(childPath); - return childPath.StartsWithF(parentPath + @"\", true) || PathUtils.IsSame(childPath, parentPath); + return childPath.StartsWith(parentPath + @"\", StringComparison.OrdinalIgnoreCase) || PathUtils.IsSame(childPath, parentPath); } } diff --git a/Tests/Utils/DirectoryUtilsTest.cs b/Tests/Utils/DirectoryUtilsTest.cs index cbb4961..10cdcaa 100644 --- a/Tests/Utils/DirectoryUtilsTest.cs +++ b/Tests/Utils/DirectoryUtilsTest.cs @@ -1,6 +1,34 @@ namespace MeloongCore.Tests; public class DirectoryUtilsTest : TestWithFolder { + [Test] + [Arguments(false)] + [Arguments(true)] + public async Task 土耳其语_目录同源及仅改大小写保留内容(bool copy) { + var originalCulture = System.Globalization.CultureInfo.CurrentCulture; + string root = tempFolder; + string source = Path.Combine(root, "FILES"); + string destination = Path.Combine(root, "files"); + try { + System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("tr-TR"); + DirectoryUtils.Create(source); + FileUtils.Write(Path.Combine(source, "keep.txt"), "目录内容"); + if (copy) { + DirectoryUtils.Copy(source, source); + DirectoryUtils.Copy(source, destination); + } else { + DirectoryUtils.Move(source, source); + DirectoryUtils.Move(source, destination); + } + await Assert.That(FileUtils.ReadAsString(Path.Combine(destination, "keep.txt"))).IsEqualTo("目录内容"); + await Assert.That(Directory.GetDirectories(PathUtils.ForApi(root)).Select(Path.GetFileName).Single()).IsEqualTo("files"); + } finally { + System.Globalization.CultureInfo.CurrentCulture = originalCulture; + DirectoryUtils.Delete(root); + } + } + + #region 剪切、复制 [Test] diff --git a/Tests/Utils/FileUtilsTest.cs b/Tests/Utils/FileUtilsTest.cs index 472c9f8..d92842b 100644 --- a/Tests/Utils/FileUtilsTest.cs +++ b/Tests/Utils/FileUtilsTest.cs @@ -1,6 +1,33 @@ namespace MeloongCore.Tests; public class FileUtilsTest : TestWithFolder { + [Test] + [Arguments(false)] + [Arguments(true)] + public async Task 土耳其语_文件同源及仅改大小写保留内容(bool copy) { + var originalCulture = System.Globalization.CultureInfo.CurrentCulture; + string root = tempFolder; + string source = Path.Combine(root, "FILE.txt"); + string destination = Path.Combine(root, "file.txt"); + try { + System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("tr-TR"); + DirectoryUtils.Create(root); + FileUtils.Write(source, "文件内容"); + if (copy) { + FileUtils.Copy(source, source); + FileUtils.Copy(source, destination); + } else { + FileUtils.Move(source, source); + FileUtils.Move(source, destination); + } + await Assert.That(FileUtils.ReadAsString(destination)).IsEqualTo("文件内容"); + await Assert.That(Directory.GetFiles(PathUtils.ForApi(root)).Select(Path.GetFileName).Single()).IsEqualTo("file.txt"); + } finally { + System.Globalization.CultureInfo.CurrentCulture = originalCulture; + DirectoryUtils.Delete(root); + } + } + [Test] public async Task 文件可用性_只读与占用() { string path = Path.Combine(tempFolder, "available.txt"); diff --git a/Tests/Utils/PathUtilsTest.cs b/Tests/Utils/PathUtilsTest.cs index 328f169..6d87d76 100644 --- a/Tests/Utils/PathUtilsTest.cs +++ b/Tests/Utils/PathUtilsTest.cs @@ -37,6 +37,31 @@ public class PathUtilsTests : TestBase { #region 路径处理 + [Test] + [Arguments("en-US")] + [Arguments("zh-CN")] + [Arguments("tr-TR")] + public async Task 路径比较_不受当前语言影响(string cultureName) { + var originalCulture = System.Globalization.CultureInfo.CurrentCulture; + try { + System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(cultureName); + await Assert.That(PathUtils.Compare(@"C:\FILES\FILE.jar", @"C:\files\file.jar")).IsEqualTo(0); + await Assert.That(PathUtils.IsSame(@"C:\FILES\FILE.jar", @"C:\files\file.jar")).IsTrue(); + await Assert.That(PathUtils.IsSame(@"C:\files\I.jar", @"C:\files\ı.jar")).IsFalse(); + await Assert.That(PathUtils.IsSame(@"C:\files\ab.jar", "C:\\files\\a\u00adb.jar")).IsFalse(); + await Assert.That(PathUtils.Compare(@"C:\files\I.jar", @"C:\files\J.jar") < 0).IsTrue(); + await Assert.That(PathUtils.IsParentOf(@"C:\FILES", @"C:\files\child")).IsTrue(); + await Assert.That(PathUtils.IsParentOf(@"C:\FILES", @"C:\files")).IsTrue(); + await Assert.That(PathUtils.IsParentOf(@"C:\FILES", @"C:\files-other\child")).IsFalse(); + await Assert.That(PathUtils.IsParentOf(@"C:\I", @"C:\ı\child")).IsFalse(); + await Assert.That(PathUtils.IsSame(null, "")).IsTrue(); + await Assert.That(PathUtils.Compare("", @"C:\files") < 0).IsTrue(); + await Assert.That(PathUtils.Compare(@"C:\files", null) > 0).IsTrue(); + } finally { + System.Globalization.CultureInfo.CurrentCulture = originalCulture; + } + } + [Test] [Arguments(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")] [Arguments(@"C:\foo\extra/bar.txt", @"C:\foo\extra")] From ae6676cd908eda599d1525e82d1372835d7d5678 Mon Sep 17 00:00:00 2001 From: Meloong Bot <110167337+HexDragon-Bot@users.noreply.github.com> Date: Sun, 11 Oct 2026 03:04:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?ref:=20=E7=B2=BE=E7=AE=80=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=AF=94=E8=BE=83=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/Utils/PathUtils.cs | 2 +- Tests/Utils/DirectoryUtilsTest.cs | 28 ---------------------------- Tests/Utils/FileUtilsTest.cs | 27 --------------------------- Tests/Utils/PathUtilsTest.cs | 25 ------------------------- 4 files changed, 1 insertion(+), 81 deletions(-) diff --git a/Shared/Utils/PathUtils.cs b/Shared/Utils/PathUtils.cs index 7ae65b3..5ee18c8 100644 --- a/Shared/Utils/PathUtils.cs +++ b/Shared/Utils/PathUtils.cs @@ -265,7 +265,7 @@ public static class PathUtils { public static bool IsParentOf(string parentPath, string childPath) { parentPath = PathUtils.ForCompare(parentPath); childPath = PathUtils.ForCompare(childPath); - return childPath.StartsWith(parentPath + @"\", StringComparison.OrdinalIgnoreCase) || PathUtils.IsSame(childPath, parentPath); + return childPath.StartsWithF(parentPath + @"\", true) || PathUtils.IsSame(childPath, parentPath); } } diff --git a/Tests/Utils/DirectoryUtilsTest.cs b/Tests/Utils/DirectoryUtilsTest.cs index 10cdcaa..cbb4961 100644 --- a/Tests/Utils/DirectoryUtilsTest.cs +++ b/Tests/Utils/DirectoryUtilsTest.cs @@ -1,34 +1,6 @@ namespace MeloongCore.Tests; public class DirectoryUtilsTest : TestWithFolder { - [Test] - [Arguments(false)] - [Arguments(true)] - public async Task 土耳其语_目录同源及仅改大小写保留内容(bool copy) { - var originalCulture = System.Globalization.CultureInfo.CurrentCulture; - string root = tempFolder; - string source = Path.Combine(root, "FILES"); - string destination = Path.Combine(root, "files"); - try { - System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("tr-TR"); - DirectoryUtils.Create(source); - FileUtils.Write(Path.Combine(source, "keep.txt"), "目录内容"); - if (copy) { - DirectoryUtils.Copy(source, source); - DirectoryUtils.Copy(source, destination); - } else { - DirectoryUtils.Move(source, source); - DirectoryUtils.Move(source, destination); - } - await Assert.That(FileUtils.ReadAsString(Path.Combine(destination, "keep.txt"))).IsEqualTo("目录内容"); - await Assert.That(Directory.GetDirectories(PathUtils.ForApi(root)).Select(Path.GetFileName).Single()).IsEqualTo("files"); - } finally { - System.Globalization.CultureInfo.CurrentCulture = originalCulture; - DirectoryUtils.Delete(root); - } - } - - #region 剪切、复制 [Test] diff --git a/Tests/Utils/FileUtilsTest.cs b/Tests/Utils/FileUtilsTest.cs index d92842b..472c9f8 100644 --- a/Tests/Utils/FileUtilsTest.cs +++ b/Tests/Utils/FileUtilsTest.cs @@ -1,33 +1,6 @@ namespace MeloongCore.Tests; public class FileUtilsTest : TestWithFolder { - [Test] - [Arguments(false)] - [Arguments(true)] - public async Task 土耳其语_文件同源及仅改大小写保留内容(bool copy) { - var originalCulture = System.Globalization.CultureInfo.CurrentCulture; - string root = tempFolder; - string source = Path.Combine(root, "FILE.txt"); - string destination = Path.Combine(root, "file.txt"); - try { - System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("tr-TR"); - DirectoryUtils.Create(root); - FileUtils.Write(source, "文件内容"); - if (copy) { - FileUtils.Copy(source, source); - FileUtils.Copy(source, destination); - } else { - FileUtils.Move(source, source); - FileUtils.Move(source, destination); - } - await Assert.That(FileUtils.ReadAsString(destination)).IsEqualTo("文件内容"); - await Assert.That(Directory.GetFiles(PathUtils.ForApi(root)).Select(Path.GetFileName).Single()).IsEqualTo("file.txt"); - } finally { - System.Globalization.CultureInfo.CurrentCulture = originalCulture; - DirectoryUtils.Delete(root); - } - } - [Test] public async Task 文件可用性_只读与占用() { string path = Path.Combine(tempFolder, "available.txt"); diff --git a/Tests/Utils/PathUtilsTest.cs b/Tests/Utils/PathUtilsTest.cs index 6d87d76..328f169 100644 --- a/Tests/Utils/PathUtilsTest.cs +++ b/Tests/Utils/PathUtilsTest.cs @@ -37,31 +37,6 @@ public class PathUtilsTests : TestBase { #region 路径处理 - [Test] - [Arguments("en-US")] - [Arguments("zh-CN")] - [Arguments("tr-TR")] - public async Task 路径比较_不受当前语言影响(string cultureName) { - var originalCulture = System.Globalization.CultureInfo.CurrentCulture; - try { - System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(cultureName); - await Assert.That(PathUtils.Compare(@"C:\FILES\FILE.jar", @"C:\files\file.jar")).IsEqualTo(0); - await Assert.That(PathUtils.IsSame(@"C:\FILES\FILE.jar", @"C:\files\file.jar")).IsTrue(); - await Assert.That(PathUtils.IsSame(@"C:\files\I.jar", @"C:\files\ı.jar")).IsFalse(); - await Assert.That(PathUtils.IsSame(@"C:\files\ab.jar", "C:\\files\\a\u00adb.jar")).IsFalse(); - await Assert.That(PathUtils.Compare(@"C:\files\I.jar", @"C:\files\J.jar") < 0).IsTrue(); - await Assert.That(PathUtils.IsParentOf(@"C:\FILES", @"C:\files\child")).IsTrue(); - await Assert.That(PathUtils.IsParentOf(@"C:\FILES", @"C:\files")).IsTrue(); - await Assert.That(PathUtils.IsParentOf(@"C:\FILES", @"C:\files-other\child")).IsFalse(); - await Assert.That(PathUtils.IsParentOf(@"C:\I", @"C:\ı\child")).IsFalse(); - await Assert.That(PathUtils.IsSame(null, "")).IsTrue(); - await Assert.That(PathUtils.Compare("", @"C:\files") < 0).IsTrue(); - await Assert.That(PathUtils.Compare(@"C:\files", null) > 0).IsTrue(); - } finally { - System.Globalization.CultureInfo.CurrentCulture = originalCulture; - } - } - [Test] [Arguments(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")] [Arguments(@"C:\foo\extra/bar.txt", @"C:\foo\extra")] From 2336fd237cb2a426de5270ea73c034ed8114da7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Sun, 11 Oct 2026 03:06:35 +0800 Subject: [PATCH 3/3] Refine comment for path comparison method Updated summary comment to remove language setting reference. --- Shared/Utils/PathUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/Utils/PathUtils.cs b/Shared/Utils/PathUtils.cs index 5ee18c8..4c77e22 100644 --- a/Shared/Utils/PathUtils.cs +++ b/Shared/Utils/PathUtils.cs @@ -232,7 +232,7 @@ public static class PathUtils { return PathUtils.Compare(path1, path2) == 0; } /// - /// 比较两个路径,忽略大小写,且不受当前语言设置影响。 + /// 比较两个路径,忽略大小写。 /// null 与空字符串视为相同的空路径,空路径排在非空路径之前。 /// ///