1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-21 23:33:00 +00:00

Fixed: Encoded unicode characters in Transmission torrent names

Closes #7270
This commit is contained in:
Mark McDowall 2024-10-05 12:26:29 -07:00
parent da610a1f40
commit 759187dcd4
5 changed files with 50 additions and 3 deletions

View file

@ -0,0 +1,20 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Common.Test.ExtensionTests.StringExtensionTests
{
[TestFixture]
public class ReplaceEncodedUnicodeCharactersFixture
{
[TestCase("+\\u2b50", "\u2b50")]
[TestCase("\\u2b50", "\u2b50")]
[TestCase("+\\u00e9", "é")]
[TestCase("\\u00e9", "é")]
[TestCase("é", "é")]
public void should_replace_encoded_unicode_character(string input, string expected)
{
input.ReplaceEncodedUnicodeCharacters().Should().Be(expected);
}
}
}

View file

@ -1,4 +1,4 @@
using FluentAssertions;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Test.Common;

View file

@ -12,6 +12,7 @@ namespace NzbDrone.Common.Extensions
public static class StringExtensions
{
private static readonly Regex CamelCaseRegex = new Regex("(?<!^)[A-Z]", RegexOptions.Compiled);
private static readonly Regex UnicodeEscapeRegex = new Regex(@"\+?\\u(?<Value>[a-z0-9]{4})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static string NullSafe(this string target)
{
@ -251,5 +252,10 @@ namespace NzbDrone.Common.Extensions
return new string(array);
}
public static string ReplaceEncodedUnicodeCharacters(this string text)
{
return UnicodeEscapeRegex.Replace(text, m => ((char)int.Parse(m.Groups["Value"].Value, NumberStyles.HexNumber)).ToString());
}
}
}

View file

@ -440,5 +440,26 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
item.CanBeRemoved.Should().BeTrue();
item.CanMoveFiles.Should().BeTrue();
}
[TestCase(@"Pok\u00e9 Bowl Complete", "Poké Bowl Complete")]
[TestCase("Pok\u00e9 Bowl Complete", "Poké Bowl Complete")]
[TestCase(@"Series with a +\u2b50", "Series with a \u2b50")]
[TestCase("Series with a \u2b50", "Series with a \u2b50")]
public void should_replace_unicode_characters(string input, string expected)
{
_completed.DownloadDir = @"/Downloads/Finished/transmission";
_completed.Name = input;
GivenTorrents(new List<TransmissionTorrent>
{
_completed
});
var items = Subject.GetItems().ToList();
items.Should().HaveCount(1);
items.First().OutputPath.Should().Be(@"/Downloads/Finished/transmission/" + expected);
}
}
}

View file

@ -66,7 +66,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
var item = new DownloadClientItem();
item.DownloadId = torrent.HashString.ToUpper();
item.Category = Settings.TvCategory;
item.Title = torrent.Name;
item.Title = torrent.Name.ReplaceEncodedUnicodeCharacters();
item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this, false);
@ -242,7 +242,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
protected virtual OsPath GetOutputPath(OsPath outputPath, TransmissionTorrent torrent)
{
return outputPath + torrent.Name.Replace(":", "_");
return outputPath + torrent.Name.ReplaceEncodedUnicodeCharacters().Replace(":", "_");
}
protected string GetDownloadDirectory()