mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-22 07:42:28 +00:00
Fixed: Normalize unicode characters when comparing paths for equality
(cherry picked from commit ceeec091f85d0094e07537b7f62f18292655a710)
This commit is contained in:
parent
abe0090f94
commit
f23d75d031
3 changed files with 16 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
@ -316,5 +317,14 @@ public void GetAncestorFolders_should_return_all_ancestors_in_path_Linux()
|
||||||
result[2].Should().Be(@"Music");
|
result[2].Should().Be(@"Music");
|
||||||
result[3].Should().Be(@"Artist Title");
|
result[3].Should().Be(@"Artist Title");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_be_equal_with_different_unicode_representations()
|
||||||
|
{
|
||||||
|
var path1 = @"C:\Test\file.mkv".AsOsAgnostic().Normalize(NormalizationForm.FormC);
|
||||||
|
var path2 = @"C:\Test\file.mkv".AsOsAgnostic().Normalize(NormalizationForm.FormD);
|
||||||
|
|
||||||
|
path1.PathEquals(path2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,10 @@ public static bool PathNotEquals(this string firstPath, string secondPath, Strin
|
||||||
|
|
||||||
public static bool PathEquals(this string firstPath, string secondPath, StringComparison? comparison = null)
|
public static bool PathEquals(this string firstPath, string secondPath, StringComparison? comparison = null)
|
||||||
{
|
{
|
||||||
|
// Normalize paths to ensure unicode characters are represented the same way
|
||||||
|
firstPath = firstPath.Normalize();
|
||||||
|
secondPath = secondPath?.Normalize();
|
||||||
|
|
||||||
if (!comparison.HasValue)
|
if (!comparison.HasValue)
|
||||||
{
|
{
|
||||||
comparison = DiskProviderBase.PathStringComparison;
|
comparison = DiskProviderBase.PathStringComparison;
|
||||||
|
|
|
@ -21,10 +21,10 @@ public int GetHashCode(string obj)
|
||||||
{
|
{
|
||||||
if (OsInfo.IsWindows)
|
if (OsInfo.IsWindows)
|
||||||
{
|
{
|
||||||
return obj.CleanFilePath().ToLower().GetHashCode();
|
return obj.CleanFilePath().Normalize().ToLower().GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj.CleanFilePath().GetHashCode();
|
return obj.CleanFilePath().Normalize().GetHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue