Merge pull request #5356 from cvium/fix_provideridextensions

return false when providerid is null or empty

(cherry picked from commit ddc62a89ba)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
pull/5640/head
Claus Vium 4 years ago committed by Joshua M. Boniface
parent 5e18ab3604
commit 046dd7fa60

@ -22,7 +22,7 @@ namespace MediaBrowser.Model.Entities
throw new ArgumentNullException(nameof(instance)); throw new ArgumentNullException(nameof(instance));
} }
return instance.ProviderIds?.ContainsKey(name) ?? false; return instance.TryGetProviderId(name, out _);
} }
/// <summary> /// <summary>
@ -56,7 +56,15 @@ namespace MediaBrowser.Model.Entities
return false; return false;
} }
return instance.ProviderIds.TryGetValue(name, out id); var foundProviderId = instance.ProviderIds.TryGetValue(name, out id);
// This occurs when searching with Identify (and possibly in other places)
if (string.IsNullOrEmpty(id))
{
id = null;
foundProviderId = false;
}
return foundProviderId;
} }
/// <summary> /// <summary>

@ -869,14 +869,14 @@ namespace MediaBrowser.Providers.Manager
} }
} }
} }
catch (Exception) #pragma warning disable CA1031 // do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // do not catch general exception types
{ {
// Logged at lower levels _logger.LogError(ex, "Provider {ProviderName} failed to retrieve search results", provider.Name);
} }
} }
// _logger.LogDebug("Returning search results {0}", _json.SerializeToString(resultList));
return resultList; return resultList;
} }

@ -18,7 +18,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact] [Fact]
public void HasProviderId_NullProvider_False() public void HasProviderId_NullProvider_False()
{ {
var nullProvider = new ProviderIdsExtensionsTestsObject() var nullProvider = new ProviderIdsExtensionsTestsObject
{ {
ProviderIds = null! ProviderIds = null!
}; };
@ -47,6 +47,15 @@ namespace Jellyfin.Model.Tests.Entities
Assert.True(provider.HasProviderId(MetadataProvider.Imdb)); Assert.True(provider.HasProviderId(MetadataProvider.Imdb));
} }
[Fact]
public void HasProviderId_FoundNameEmptyValue_False()
{
var provider = new ProviderIdsExtensionsTestsObject();
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = string.Empty;
Assert.False(provider.HasProviderId(MetadataProvider.Imdb));
}
[Fact] [Fact]
public void GetProviderId_NullInstance_ThrowsArgumentNullException() public void GetProviderId_NullInstance_ThrowsArgumentNullException()
{ {
@ -68,7 +77,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact] [Fact]
public void GetProviderId_NullProvider_Null() public void GetProviderId_NullProvider_Null()
{ {
var nullProvider = new ProviderIdsExtensionsTestsObject() var nullProvider = new ProviderIdsExtensionsTestsObject
{ {
ProviderIds = null! ProviderIds = null!
}; };
@ -85,7 +94,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact] [Fact]
public void TryGetProviderId_NullProvider_False() public void TryGetProviderId_NullProvider_False()
{ {
var nullProvider = new ProviderIdsExtensionsTestsObject() var nullProvider = new ProviderIdsExtensionsTestsObject
{ {
ProviderIds = null! ProviderIds = null!
}; };
@ -112,6 +121,16 @@ namespace Jellyfin.Model.Tests.Entities
Assert.Equal(ExampleImdbId, id); Assert.Equal(ExampleImdbId, id);
} }
[Fact]
public void TryGetProviderId_FoundNameEmptyValue_False()
{
var provider = new ProviderIdsExtensionsTestsObject();
provider.ProviderIds[MetadataProvider.Imdb.ToString()] = string.Empty;
Assert.False(provider.TryGetProviderId(MetadataProvider.Imdb, out var id));
Assert.Null(id);
}
[Fact] [Fact]
public void SetProviderId_NullInstance_ThrowsArgumentNullException() public void SetProviderId_NullInstance_ThrowsArgumentNullException()
{ {
@ -146,7 +165,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact] [Fact]
public void SetProviderId_NullProvider_Success() public void SetProviderId_NullProvider_Success()
{ {
var nullProvider = new ProviderIdsExtensionsTestsObject() var nullProvider = new ProviderIdsExtensionsTestsObject
{ {
ProviderIds = null! ProviderIds = null!
}; };
@ -158,7 +177,7 @@ namespace Jellyfin.Model.Tests.Entities
[Fact] [Fact]
public void SetProviderId_NullProviderAndEmptyName_Success() public void SetProviderId_NullProviderAndEmptyName_Success()
{ {
var nullProvider = new ProviderIdsExtensionsTestsObject() var nullProvider = new ProviderIdsExtensionsTestsObject
{ {
ProviderIds = null! ProviderIds = null!
}; };

Loading…
Cancel
Save