From d7dddf6009cd3b98ab01afa8852f457e2c41c7dc Mon Sep 17 00:00:00 2001 From: Cory Date: Tue, 24 Mar 2020 21:39:38 -0500 Subject: [PATCH] core: remove string extensions in favor of explicit conversion (#7839) --- src/Jackett.Common/Indexers/720pier.cs | 2 +- src/Jackett.Common/Indexers/AniDub.cs | 6 ++--- .../Indexers/Feeds/AnimeTosho.cs | 2 +- .../Indexers/Feeds/BaseFeedIndexer.cs | 2 +- .../Indexers/Feeds/BaseNewznabIndexer.cs | 11 +++++----- src/Jackett.Common/Indexers/TorrentNetwork.cs | 2 +- .../Models/DTO/TorznabRequest.cs | 22 +++++++++---------- .../Services/IndexerManagerService.cs | 2 +- src/Jackett.Common/Utils/Extensions.cs | 11 ---------- .../Controllers/IndexerApiController.cs | 2 +- .../Controllers/ResultsController.cs | 2 +- 11 files changed, 27 insertions(+), 37 deletions(-) diff --git a/src/Jackett.Common/Indexers/720pier.cs b/src/Jackett.Common/Indexers/720pier.cs index 689fbc5f6..a8e1c3ef2 100644 --- a/src/Jackett.Common/Indexers/720pier.cs +++ b/src/Jackett.Common/Indexers/720pier.cs @@ -211,7 +211,7 @@ namespace Jackett.Common.Indexers var author = row.QuerySelector("dd.lastpost > span"); var timestr = author.TextContent.Split('\n') - .Where(str => !str.IsNullOrEmptyOrWhitespace()) //Filter blank lines + .Where(str => !string.IsNullOrWhiteSpace(str)) //Filter blank lines .Skip(1) //Skip author name .FirstOrDefault() .Trim(); diff --git a/src/Jackett.Common/Indexers/AniDub.cs b/src/Jackett.Common/Indexers/AniDub.cs index 3c741d713..87fd382b7 100644 --- a/src/Jackett.Common/Indexers/AniDub.cs +++ b/src/Jackett.Common/Indexers/AniDub.cs @@ -136,7 +136,7 @@ namespace Jackett.Common.Indexers // If the search string is empty use the latest releases protected override async Task> PerformQuery(TorznabQuery query) - => query.IsTest || query.SearchTerm.IsNullOrEmptyOrWhitespace() + => query.IsTest || string.IsNullOrWhiteSpace(query.SearchTerm) ? await FetchNewReleases() : await PerformSearch(query); @@ -313,7 +313,7 @@ namespace Jackett.Common.Indexers var releaseNode = tabNode.ParentElement; var quality = GetQuality(releaseNode); - if (!quality.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(quality)) { return $"{baseTitle} [{quality}]"; } @@ -324,7 +324,7 @@ namespace Jackett.Common.Indexers private static string GetQuality(IElement releaseNode) { // For some releases there's no block with quality - if (releaseNode.Id.IsNullOrEmptyOrWhitespace()) + if (string.IsNullOrWhiteSpace(releaseNode.Id)) { return null; } diff --git a/src/Jackett.Common/Indexers/Feeds/AnimeTosho.cs b/src/Jackett.Common/Indexers/Feeds/AnimeTosho.cs index 81eaff308..bf1a2ceaf 100644 --- a/src/Jackett.Common/Indexers/Feeds/AnimeTosho.cs +++ b/src/Jackett.Common/Indexers/Feeds/AnimeTosho.cs @@ -47,7 +47,7 @@ namespace Jackett.Common.Indexers.Feeds if (enclosures.Any()) { var enclosure = enclosures.First().Attribute("url").Value; - release.Link = enclosure.ToUri(); + release.Link = new Uri(enclosure); } // add some default values if none returned by feed release.Seeders = release.Seeders > 0 ? release.Seeders : 0; diff --git a/src/Jackett.Common/Indexers/Feeds/BaseFeedIndexer.cs b/src/Jackett.Common/Indexers/Feeds/BaseFeedIndexer.cs index 605518ce8..7d86e24b6 100644 --- a/src/Jackett.Common/Indexers/Feeds/BaseFeedIndexer.cs +++ b/src/Jackett.Common/Indexers/Feeds/BaseFeedIndexer.cs @@ -32,7 +32,7 @@ namespace Jackett.Common.Indexers.Feeds protected override async Task> PerformQuery(TorznabQuery query) { var requestUri = FeedUri.ToString(); - if (!query.SearchTerm.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(query.SearchTerm)) requestUri = requestUri + "?q=" + query.SearchTerm; var request = new WebRequest { diff --git a/src/Jackett.Common/Indexers/Feeds/BaseNewznabIndexer.cs b/src/Jackett.Common/Indexers/Feeds/BaseNewznabIndexer.cs index b5e5858b3..84678b4c5 100644 --- a/src/Jackett.Common/Indexers/Feeds/BaseNewznabIndexer.cs +++ b/src/Jackett.Common/Indexers/Feeds/BaseNewznabIndexer.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; @@ -31,10 +32,10 @@ namespace Jackett.Common.Indexers.Feeds var release = new ReleaseInfo { Title = item.FirstValue("title"), - Guid = item.FirstValue("guid").ToUri(), - Link = item.FirstValue("link").ToUri(), - Comments = item.FirstValue("comments").ToUri(), - PublishDate = item.FirstValue("pubDate").ToDateTime(), + Guid = new Uri(item.FirstValue("guid")), + Link = new Uri(item.FirstValue("link")), + Comments = new Uri(item.FirstValue("comments")), + PublishDate = DateTime.Parse(item.FirstValue("pubDate")), Category = new List { int.Parse(attributes.First(e => e.Attribute("name").Value == "category").Attribute("value").Value) }, Size = ReadAttribute(attributes, "size").TryParse(), Files = ReadAttribute(attributes, "files").TryParse(), @@ -42,7 +43,7 @@ namespace Jackett.Common.Indexers.Feeds Seeders = ReadAttribute(attributes, "seeders").TryParse(), Peers = ReadAttribute(attributes, "peers").TryParse(), InfoHash = attributes.First(e => e.Attribute("name").Value == "infohash").Attribute("value").Value, - MagnetUri = attributes.First(e => e.Attribute("name").Value == "magneturl").Attribute("value").Value.ToUri(), + MagnetUri = new Uri(attributes.First(e => e.Attribute("name").Value == "magneturl").Attribute("value").Value), }; return release; } diff --git a/src/Jackett.Common/Indexers/TorrentNetwork.cs b/src/Jackett.Common/Indexers/TorrentNetwork.cs index 07a3714c7..f6165b016 100644 --- a/src/Jackett.Common/Indexers/TorrentNetwork.cs +++ b/src/Jackett.Common/Indexers/TorrentNetwork.cs @@ -183,7 +183,7 @@ namespace Jackett.Common.Indexers searchUrl += "?" + queryCollection.GetQueryString(); - if (passkey.IsNullOrEmptyOrWhitespace()) + if (string.IsNullOrWhiteSpace(passkey)) await ApplyConfiguration(null); var result = await SendAPIRequest(searchUrl, null); diff --git a/src/Jackett.Common/Models/DTO/TorznabRequest.cs b/src/Jackett.Common/Models/DTO/TorznabRequest.cs index 3843cad93..00f08e1b5 100644 --- a/src/Jackett.Common/Models/DTO/TorznabRequest.cs +++ b/src/Jackett.Common/Models/DTO/TorznabRequest.cs @@ -34,11 +34,11 @@ namespace Jackett.Common.Models.DTO }; if (request.t != null) query.QueryType = request.t; - if (!request.extended.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.extended)) query.Extended = ParseUtil.CoerceInt(request.extended); - if (!request.limit.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.limit)) query.Limit = ParseUtil.CoerceInt(request.limit); - if (!request.offset.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.offset)) query.Offset = ParseUtil.CoerceInt(request.offset); if (request.cat != null) @@ -53,23 +53,23 @@ namespace Jackett.Common.Models.DTO query.Categories = new int[0]; } - if (!request.rid.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.rid)) query.RageID = int.Parse(request.rid); - if (!request.season.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.season)) query.Season = int.Parse(request.season); - if (!request.album.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.album)) query.Album = request.album; - if (!request.artist.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.artist)) query.Artist = request.artist; - if (!request.label.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.label)) query.Label = request.label; - if (!request.track.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.track)) query.Track = request.track; - if (!request.year.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.year)) query.Year = int.Parse(request.year); - if (!request.genre.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(request.genre)) query.Genre = request.genre.Split(','); query.ExpandCatsToSubCats(); diff --git a/src/Jackett.Common/Services/IndexerManagerService.cs b/src/Jackett.Common/Services/IndexerManagerService.cs index d2f79a669..25860bcf5 100644 --- a/src/Jackett.Common/Services/IndexerManagerService.cs +++ b/src/Jackett.Common/Services/IndexerManagerService.cs @@ -159,7 +159,7 @@ namespace Jackett.Common.Services var omdbApiKey = serverConfig.OmdbApiKey; IFallbackStrategyProvider fallbackStrategyProvider = null; IResultFilterProvider resultFilterProvider = null; - if (!omdbApiKey.IsNullOrEmptyOrWhitespace()) + if (!string.IsNullOrWhiteSpace(omdbApiKey)) { var imdbResolver = new OmdbResolver(webClient, omdbApiKey.ToNonNull(), serverConfig.OmdbApiUrl); fallbackStrategyProvider = new ImdbFallbackStrategyProvider(imdbResolver); diff --git a/src/Jackett.Common/Utils/Extensions.cs b/src/Jackett.Common/Utils/Extensions.cs index 0de08f589..cff7e1e1f 100644 --- a/src/Jackett.Common/Utils/Extensions.cs +++ b/src/Jackett.Common/Utils/Extensions.cs @@ -48,17 +48,6 @@ namespace Jackett.Common.Utils public static IEnumerable Flatten(this IEnumerable> list) => list.SelectMany(x => x); } - // TODO This class should be removed in favor of explicit conversions - public static class StringExtension - { - // string.IsNullOrWhitespace already checks string.IsNullOrEmpty should remove this? - public static bool IsNullOrEmptyOrWhitespace(this string str) => string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str); - - public static DateTime ToDateTime(this string str) => DateTime.Parse(str); - - public static Uri ToUri(this string str) => new Uri(str); - } - public static class CollectionExtension { // IEnumerable class above already does this. All ICollection are IEnumerable, so favor IEnumerable? diff --git a/src/Jackett.Server/Controllers/IndexerApiController.cs b/src/Jackett.Server/Controllers/IndexerApiController.cs index 8c17f0e05..97e8d7e6b 100644 --- a/src/Jackett.Server/Controllers/IndexerApiController.cs +++ b/src/Jackett.Server/Controllers/IndexerApiController.cs @@ -39,7 +39,7 @@ namespace Jackett.Server.Controllers } var indexerId = parameters["indexerId"] as string; - if (indexerId.IsNullOrEmptyOrWhitespace()) + if (string.IsNullOrWhiteSpace(indexerId)) return; var indexerService = indexerController.IndexerService; diff --git a/src/Jackett.Server/Controllers/ResultsController.cs b/src/Jackett.Server/Controllers/ResultsController.cs index 1ba070248..29ccd0fb3 100644 --- a/src/Jackett.Server/Controllers/ResultsController.cs +++ b/src/Jackett.Server/Controllers/ResultsController.cs @@ -71,7 +71,7 @@ namespace Jackett.Server.Controllers } var indexerId = parameters["indexerId"] as string; - if (indexerId.IsNullOrEmptyOrWhitespace()) + if (string.IsNullOrWhiteSpace(indexerId)) { indexerController.CurrentIndexer = null; context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.NotFound, 201, "Indexer is not specified (empty value)");