Fix some CodeQL issues

This commit is contained in:
Pithaya 2023-10-20 21:38:09 +02:00
parent 822feebad1
commit 8fbb1a54f9
3 changed files with 16 additions and 11 deletions

View File

@ -430,14 +430,14 @@ namespace Jellyfin.Plugin.Bookshelf.Providers.GoogleBooks
item.IndexNumber = index;
}
if (match.Groups.ContainsKey("name"))
if (match.Groups.TryGetValue("name", out Group? nameGroup))
{
item.Name = match.Groups["name"].Value.Trim();
item.Name = nameGroup.Value.Trim();
}
if (match.Groups.ContainsKey("seriesName"))
if (match.Groups.TryGetValue("seriesName", out Group? seriesGroup))
{
item.SeriesName = match.Groups["seriesName"].Value.Trim();
item.SeriesName = seriesGroup.Value.Trim();
}
// might as well catch the return value here as well

View File

@ -18,7 +18,8 @@ namespace Jellyfin.Plugin.Bookshelf.Tests
});
var mockedHttpClientFactory = Substitute.For<IHttpClientFactory>();
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(new HttpClient(mockedMessageHandler));
using var client = new HttpClient(mockedMessageHandler);
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(client);
IRemoteImageProvider provider = new GoogleBooksImageProvider(mockedHttpClientFactory);

View File

@ -20,8 +20,8 @@ namespace Jellyfin.Plugin.Bookshelf.Tests
private bool HasGoogleId(string id, Dictionary<string, string> providerIds)
{
return providerIds.Count == 1
&& providerIds.ContainsKey(GoogleBooksConstants.ProviderId)
&& providerIds[GoogleBooksConstants.ProviderId] == id;
&& providerIds.TryGetValue(GoogleBooksConstants.ProviderId, out var providerId)
&& providerId == id;
}
#region GetSearchResults
@ -35,7 +35,8 @@ namespace Jellyfin.Plugin.Bookshelf.Tests
});
var mockedHttpClientFactory = Substitute.For<IHttpClientFactory>();
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(new HttpClient(mockedMessageHandler));
using var client = new HttpClient(mockedMessageHandler);
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(client);
IRemoteMetadataProvider<Book, BookInfo> provider = new GoogleBooksProvider(NullLogger<GoogleBooksProvider>.Instance, mockedHttpClientFactory);
@ -78,7 +79,8 @@ namespace Jellyfin.Plugin.Bookshelf.Tests
});
var mockedHttpClientFactory = Substitute.For<IHttpClientFactory>();
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(new HttpClient(mockedMessageHandler));
using var client = new HttpClient(mockedMessageHandler);
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(client);
IRemoteMetadataProvider<Book, BookInfo> provider = new GoogleBooksProvider(NullLogger<GoogleBooksProvider>.Instance, mockedHttpClientFactory);
@ -133,7 +135,8 @@ namespace Jellyfin.Plugin.Bookshelf.Tests
});
var mockedHttpClientFactory = Substitute.For<IHttpClientFactory>();
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(new HttpClient(mockedMessageHandler));
using var client = new HttpClient(mockedMessageHandler);
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(client);
IRemoteMetadataProvider<Book, BookInfo> provider = new GoogleBooksProvider(NullLogger<GoogleBooksProvider>.Instance, mockedHttpClientFactory);
@ -187,7 +190,8 @@ namespace Jellyfin.Plugin.Bookshelf.Tests
});
var mockedHttpClientFactory = Substitute.For<IHttpClientFactory>();
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(new HttpClient(mockedMessageHandler));
using var client = new HttpClient(mockedMessageHandler);
mockedHttpClientFactory.CreateClient(Arg.Any<string>()).Returns(client);
IRemoteMetadataProvider<Book, BookInfo> provider = new GoogleBooksProvider(NullLogger<GoogleBooksProvider>.Instance, mockedHttpClientFactory);