1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 07:22:35 +01:00

Fixed: Prevent errors parsing releases in unexpected formats

This commit is contained in:
Mark McDowall 2024-06-21 17:10:10 -07:00 committed by Mark McDowall
parent a0d2933134
commit 45fe585944
2 changed files with 30 additions and 3 deletions

View File

@ -39,6 +39,13 @@ namespace NzbDrone.Core.Test.ParserTests
ExceptionVerification.IgnoreWarns(); ExceptionVerification.IgnoreWarns();
} }
[TestCase("علم نف) أ.دعادل الأبيض ٢٠٢٤ ٣ ٣")]
[TestCase("ror-240618_1007-1022-")]
public void should_parse_unknown_formats_without_error(string title)
{
Parser.Parser.ParseTitle(title).Should().NotBeNull();
}
[Test] [Test]
public void should_not_parse_md5() public void should_not_parse_md5()
{ {

View File

@ -745,7 +745,7 @@ namespace NzbDrone.Core.Parser
Logger.Trace(regex); Logger.Trace(regex);
try try
{ {
var result = ParseMatchCollection(match, releaseTitle); var result = ParseMatchCollection(match, simpleTitle);
if (result != null) if (result != null)
{ {
@ -1209,6 +1209,7 @@ namespace NzbDrone.Core.Parser
} }
} }
// TODO: This needs to check the modified title
if (lastSeasonEpisodeStringIndex != releaseTitle.Length) if (lastSeasonEpisodeStringIndex != releaseTitle.Length)
{ {
result.ReleaseTokens = releaseTitle.Substring(lastSeasonEpisodeStringIndex); result.ReleaseTokens = releaseTitle.Substring(lastSeasonEpisodeStringIndex);
@ -1289,7 +1290,7 @@ namespace NzbDrone.Core.Parser
private static int ParseNumber(string value) private static int ParseNumber(string value)
{ {
var normalized = value.Normalize(NormalizationForm.FormKC); var normalized = ConvertToNumerals(value.Normalize(NormalizationForm.FormKC));
if (int.TryParse(normalized, out var number)) if (int.TryParse(normalized, out var number))
{ {
@ -1308,7 +1309,7 @@ namespace NzbDrone.Core.Parser
private static decimal ParseDecimal(string value) private static decimal ParseDecimal(string value)
{ {
var normalized = value.Normalize(NormalizationForm.FormKC); var normalized = ConvertToNumerals(value.Normalize(NormalizationForm.FormKC));
if (decimal.TryParse(normalized, NumberStyles.Float, CultureInfo.InvariantCulture, out var number)) if (decimal.TryParse(normalized, NumberStyles.Float, CultureInfo.InvariantCulture, out var number))
{ {
@ -1317,5 +1318,24 @@ namespace NzbDrone.Core.Parser
throw new FormatException(string.Format("{0} isn't a number", value)); throw new FormatException(string.Format("{0} isn't a number", value));
} }
private static string ConvertToNumerals(string input)
{
var result = new StringBuilder(input.Length);
foreach (var c in input.ToCharArray())
{
if (char.IsNumber(c))
{
result.Append(char.GetNumericValue(c));
}
else
{
result.Append(c);
}
}
return result.ToString();
}
} }
} }