1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-08-18 16:29:41 +02:00

Better validation for Imdb Ids from lists

Fixes #5674
This commit is contained in:
Qstick 2021-01-06 23:06:07 -05:00
parent 99b75a3089
commit 88ec106ec6
3 changed files with 15 additions and 0 deletions

View File

@ -162,6 +162,7 @@ public void should_parse_imdb_in_title(string postTitle, string imdb)
parsed.ImdbId.Should().Be(imdb);
}
[TestCase("asfd", null)]
[TestCase("123", "tt0000123")]
[TestCase("1234567", "tt1234567")]
[TestCase("tt1234567", "tt1234567")]

View File

@ -125,6 +125,13 @@ public List<Movie> GetBulkMovieInfo(List<int> tmdbIds)
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())

View File

@ -357,6 +357,13 @@ public static string ReplaceGermanUmlauts(string s)
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');