1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 07:52:37 +01:00

Prevent exception parsing unicode digits in absolute numbers.

This commit is contained in:
Taloth Saldono 2020-05-02 14:20:49 +02:00
parent 0b1e99991e
commit f282ae8aae
2 changed files with 35 additions and 5 deletions

View File

@ -67,5 +67,17 @@ namespace NzbDrone.Core.Test.ParserTests
result.SeriesTitle.Should().Be(title); result.SeriesTitle.Should().Be(title);
result.FullSeason.Should().BeFalse(); result.FullSeason.Should().BeFalse();
} }
[TestCase("[Subz] My Series - [h264 10-bit][1080p]", "My Series", 158)]
public void should_parse_unicode_digits(string postTitle, string title, int absoluteEpisodeNumber)
{
var result = Parser.Parser.ParseTitle(postTitle);
result.Should().NotBeNull();
result.SeriesTitle.Should().Be(title);
result.AbsoluteEpisodeNumbers.Should().NotBeEmpty();
result.AbsoluteEpisodeNumbers.Should().BeEquivalentTo(new[] { absoluteEpisodeNumber });
result.SpecialAbsoluteEpisodeNumbers.Should().BeEmpty();
result.FullSeason.Should().BeFalse();
}
} }
} }

View File

@ -10,6 +10,7 @@ using NzbDrone.Common.Instrumentation;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
using System.Text;
namespace NzbDrone.Core.Parser namespace NzbDrone.Core.Parser
{ {
@ -657,7 +658,7 @@ namespace NzbDrone.Core.Parser
return title; return title;
} }
private static SeriesTitleInfo GetSeriesTitleInfo(string title) private static SeriesTitleInfo GetSeriesTitleInfo(string title)
{ {
var seriesTitleInfo = new SeriesTitleInfo(); var seriesTitleInfo = new SeriesTitleInfo();
@ -748,8 +749,8 @@ namespace NzbDrone.Core.Parser
if (absoluteEpisodeCaptures.Any()) if (absoluteEpisodeCaptures.Any())
{ {
var first = Convert.ToDecimal(absoluteEpisodeCaptures.First().Value, CultureInfo.InvariantCulture); var first = ParseDecimal(absoluteEpisodeCaptures.First().Value);
var last = Convert.ToDecimal(absoluteEpisodeCaptures.Last().Value, CultureInfo.InvariantCulture); var last = ParseDecimal(absoluteEpisodeCaptures.Last().Value);
if (first > last) if (first > last)
{ {
@ -816,7 +817,7 @@ namespace NzbDrone.Core.Parser
//Try to Parse as a daily show //Try to Parse as a daily show
var airmonth = Convert.ToInt32(matchCollection[0].Groups["airmonth"].Value); var airmonth = Convert.ToInt32(matchCollection[0].Groups["airmonth"].Value);
var airday = Convert.ToInt32(matchCollection[0].Groups["airday"].Value); var airday = Convert.ToInt32(matchCollection[0].Groups["airday"].Value);
//Swap day and month if month is bigger than 12 (scene fail) //Swap day and month if month is bigger than 12 (scene fail)
if (airmonth > 12) if (airmonth > 12)
{ {
@ -936,7 +937,9 @@ namespace NzbDrone.Core.Parser
{ {
int number; int number;
if (int.TryParse(value, out number)) var normalized = value.Normalize(NormalizationForm.FormKC);
if (int.TryParse(normalized, out number))
{ {
return number; return number;
} }
@ -948,6 +951,21 @@ namespace NzbDrone.Core.Parser
return number; return number;
} }
throw new FormatException(string.Format("{0} isn't a number", value));
}
private static decimal ParseDecimal(string value)
{
decimal number;
var normalized = value.Normalize(NormalizationForm.FormKC);
if (decimal.TryParse(normalized, NumberStyles.Float, CultureInfo.InvariantCulture, out number))
{
return number;
}
throw new FormatException(string.Format("{0} isn't a number", value)); throw new FormatException(string.Format("{0} isn't a number", value));
} }
} }