From 58abb6fbc272aaa76fe190cb1791d1243a0fc511 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 8 Dec 2011 00:44:22 -0800 Subject: [PATCH] SearchForSeries won't fail if an apostrophe is used in the search term (Let's PetaPoco handle building the query, as it should). --- .../ProviderTests/SeriesProviderTest.cs | 25 +++++++++++++++++++ NzbDrone.Core/Providers/SeriesProvider.cs | 8 +++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs index fd4485512..61dc33105 100644 --- a/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs @@ -721,5 +721,30 @@ public void SearchForSeries_should_not_return_results_that_do_not_contain_the_qu //Assert series.Should().HaveCount(0); } + + [Test] + public void SearchForSeries_should_return_results_when_query_has_special_characters() + { + var mocker = new AutoMoqer(MockBehavior.Strict); + var db = TestDbHelper.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeQuality = Builder.CreateNew().Build(); + var fakeSeries = Builder.CreateListOfSize(10) + .All() + .With(e => e.QualityProfileId = fakeQuality.QualityProfileId) + .TheLast(1) + .With(s => s.Title = "It's Always Sunny") + .Build(); + + db.InsertMany(fakeSeries); + db.Insert(fakeQuality); + + //Act + var series = mocker.Resolve().SearchForSeries("it's"); + + //Assert + series.Should().HaveCount(1); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index 4fd1e9c08..82e2e4ead 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -186,11 +186,11 @@ public virtual bool SeriesPathExists(string cleanPath) public virtual List SearchForSeries(string title) { - var query = String.Format(@"SELECT * FROM Series - INNER JOIN QualityProfiles ON Series.QualityProfileId = QualityProfiles.QualityProfileId - WHERE Title LIKE '%{0}%'", title); + var query = String.Format("%{0}%", title); - var series = _database.Fetch(query); + var series = _database.Fetch(@"SELECT * FROM Series + INNER JOIN QualityProfiles ON Series.QualityProfileId = QualityProfiles.QualityProfileId + WHERE Title LIKE @0", query); return series; }