From bf2ef02998a208d5a675a711afcd6250e8df824c Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Sat, 9 Apr 2022 23:16:20 -0500 Subject: [PATCH] Fixed: Escape Characters as needed for *znab queries (cherry picked from commit f678775e5c3deb0c520f88a137198331fee2831f) --- .../NewznabRequestGeneratorFixture.cs | 35 +++++++++++++++++++ .../Newznab/NewznabRequestGenerator.cs | 3 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs index 39bd839a0..30edcd44a 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs @@ -61,5 +61,40 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests page.Url.Query.Should().Contain("artist=Alien%20Ant%20Farm"); page.Url.Query.Should().Contain("album=TruANT"); } + + [Test] + public void should_encode_raw_title() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "season", "ep" }; + _capabilities.TvTextSearchEngine = "raw"; + _singleEpisodeSearchCriteria.SceneTitles[0] = "Edith & Little"; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.Tiers.Should().Be(1); + + var pageTier = results.GetTier(0).First().First(); + + pageTier.Url.Query.Should().Contain("q=Edith%20%26%20Little"); + pageTier.Url.Query.Should().NotContain(" & "); + pageTier.Url.Query.Should().Contain("%26"); + } + + [Test] + public void should_use_clean_title_and_encode() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "season", "ep" }; + _capabilities.TvTextSearchEngine = "sphinx"; + _singleEpisodeSearchCriteria.SceneTitles[0] = "Edith & Little"; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.Tiers.Should().Be(1); + + var pageTier = results.GetTier(0).First().First(); + + pageTier.Url.Query.Should().Contain("q=Edith%20and%20Little"); + pageTier.Url.Query.Should().Contain("and"); + pageTier.Url.Query.Should().NotContain(" & "); + pageTier.Url.Query.Should().NotContain("%26"); + } } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs index f7f167b34..500894951 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs @@ -151,7 +151,8 @@ namespace NzbDrone.Core.Indexers.Newznab private static string NewsnabifyTitle(string title) { - return title.Replace("+", "%20"); + title = title.Replace("+", " "); + return Uri.EscapeDataString(title); } } }