mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-29 23:12:39 +01:00
Fixed: Prevent errors parsing releases in unexpected formats
This commit is contained in:
parent
a0d2933134
commit
45fe585944
@ -39,6 +39,13 @@ namespace NzbDrone.Core.Test.ParserTests
|
||||
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]
|
||||
public void should_not_parse_md5()
|
||||
{
|
||||
|
@ -745,7 +745,7 @@ namespace NzbDrone.Core.Parser
|
||||
Logger.Trace(regex);
|
||||
try
|
||||
{
|
||||
var result = ParseMatchCollection(match, releaseTitle);
|
||||
var result = ParseMatchCollection(match, simpleTitle);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
@ -1209,6 +1209,7 @@ namespace NzbDrone.Core.Parser
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This needs to check the modified title
|
||||
if (lastSeasonEpisodeStringIndex != releaseTitle.Length)
|
||||
{
|
||||
result.ReleaseTokens = releaseTitle.Substring(lastSeasonEpisodeStringIndex);
|
||||
@ -1289,7 +1290,7 @@ namespace NzbDrone.Core.Parser
|
||||
|
||||
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))
|
||||
{
|
||||
@ -1308,7 +1309,7 @@ namespace NzbDrone.Core.Parser
|
||||
|
||||
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))
|
||||
{
|
||||
@ -1317,5 +1318,24 @@ namespace NzbDrone.Core.Parser
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user