From 88ec106ec6b238588bc866c92f34b9b0021b69f5 Mon Sep 17 00:00:00 2001 From: Qstick Date: Wed, 6 Jan 2021 23:06:07 -0500 Subject: [PATCH] Better validation for Imdb Ids from lists Fixes #5674 --- src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs | 1 + src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs | 7 +++++++ src/NzbDrone.Core/Parser/Parser.cs | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs index 7ca7a4c70..effb96cca 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs @@ -162,6 +162,7 @@ namespace NzbDrone.Core.Test.ParserTests parsed.ImdbId.Should().Be(imdb); } + [TestCase("asfd", null)] [TestCase("123", "tt0000123")] [TestCase("1234567", "tt1234567")] [TestCase("tt1234567", "tt1234567")] diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index ca7189684..b50c07800 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -125,6 +125,13 @@ namespace NzbDrone.Core.MetadataSource.SkyHook public Movie GetMovieByImdbId(string imdbId) { + imdbId = Parser.Parser.NormalizeImdbId(imdbId); + + if (imdbId == null) + { + return null; + } + var httpRequest = _radarrMetadata.Create() .SetSegment("route", "movie/imdb") .Resource(imdbId.ToString()) diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index e659b9e6b..2986c5dfc 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -357,6 +357,13 @@ namespace NzbDrone.Core.Parser public static string NormalizeImdbId(string imdbId) { + var imdbRegex = new Regex(@"^(\d{1,10}|(tt)\d{1,10})$"); + + if (!imdbRegex.IsMatch(imdbId)) + { + return null; + } + if (imdbId.Length > 2) { imdbId = imdbId.Replace("tt", "").PadLeft(7, '0');