From d3874e6646ce5dc223df76fa333f16af52978d0f Mon Sep 17 00:00:00 2001 From: Dagizmo Date: Thu, 24 Oct 2019 13:59:32 -0700 Subject: [PATCH 1/4] fix language with spaces giving wrong results --- Octokit/Models/Request/SearchCodeRequest.cs | 2 +- Octokit/Models/Request/SearchIssuesRequest.cs | 2 +- Octokit/Models/Request/SearchIssuesRequestExclusions.cs | 2 +- Octokit/Models/Request/SearchRepositoriesRequest.cs | 2 +- Octokit/Models/Request/SearchUsersRequest.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Octokit/Models/Request/SearchCodeRequest.cs b/Octokit/Models/Request/SearchCodeRequest.cs index 22a92354a5..9c4795fa67 100644 --- a/Octokit/Models/Request/SearchCodeRequest.cs +++ b/Octokit/Models/Request/SearchCodeRequest.cs @@ -169,7 +169,7 @@ public override IReadOnlyList MergedQualifiers() if (Language != null) { - parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language.ToParameter())); + parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter())); } if (Forks != null) diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index a644cdc6b0..2600e27472 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -338,7 +338,7 @@ public override IReadOnlyList MergedQualifiers() if (Language != null) { - parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language.ToParameter())); + parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter())); } if (Is != null) diff --git a/Octokit/Models/Request/SearchIssuesRequestExclusions.cs b/Octokit/Models/Request/SearchIssuesRequestExclusions.cs index 38815a2a65..4362c3e206 100644 --- a/Octokit/Models/Request/SearchIssuesRequestExclusions.cs +++ b/Octokit/Models/Request/SearchIssuesRequestExclusions.cs @@ -170,7 +170,7 @@ public IReadOnlyList MergedQualifiers() if (Language != null) { - parameters.Add(string.Format(CultureInfo.InvariantCulture, "-language:{0}", Language.ToParameter())); + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-language:\"{0}\"", Language.ToParameter())); } if (Status.HasValue) diff --git a/Octokit/Models/Request/SearchRepositoriesRequest.cs b/Octokit/Models/Request/SearchRepositoriesRequest.cs index 3e88ab8bb7..1e0b8e939c 100644 --- a/Octokit/Models/Request/SearchRepositoriesRequest.cs +++ b/Octokit/Models/Request/SearchRepositoriesRequest.cs @@ -148,7 +148,7 @@ public override IReadOnlyList MergedQualifiers() if (Language != null) { - parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language.ToParameter())); + parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter())); } if (User.IsNotBlank()) diff --git a/Octokit/Models/Request/SearchUsersRequest.cs b/Octokit/Models/Request/SearchUsersRequest.cs index 3d8d783647..0dad61db4f 100644 --- a/Octokit/Models/Request/SearchUsersRequest.cs +++ b/Octokit/Models/Request/SearchUsersRequest.cs @@ -117,7 +117,7 @@ public override IReadOnlyList MergedQualifiers() if (Language != null) { - parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language)); + parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language)); } if (Created != null) From 08f849363f826601d295b9ab575fac0bb31ee371 Mon Sep 17 00:00:00 2001 From: Dagizmo Date: Thu, 24 Oct 2019 14:04:34 -0700 Subject: [PATCH 2/4] support test for language fix --- Octokit.Tests/Clients/SearchClientTests.cs | 8 ++++---- .../Models/SearchIssuesRequestExclusionsTests.cs | 2 +- Octokit.Tests/Models/SearchIssuesRequestTests.cs | 2 +- Octokit.Tests/Models/SearchRepositoryRequestTests.cs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index a7e03ec72c..24ee618a78 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -206,7 +206,7 @@ public void TestingTheLanguageQualifier() client.SearchUsers(request); connection.Received().Get( Arg.Is(u => u.ToString() == "search/users"), - Arg.Is>(d => d["q"] == "github+language:Ruby")); + Arg.Is>(d => d["q"] == "github+language:\"Ruby\"")); } [Fact] @@ -467,7 +467,7 @@ public void TestingTheLangaugeQualifier() request.Language = Language.Ruby; client.SearchRepo(request); connection.Received().Get(Arg.Is(u => u.ToString() == "search/repositories"), - Arg.Is>(d => d["q"] == "github+language:ruby")); + Arg.Is>(d => d["q"] == "github+language:\"ruby\"")); } [Fact] @@ -992,7 +992,7 @@ public void TestingTheLanguageQualifier() connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), - Arg.Is>(d => d["q"] == "something+language:CSharp")); + Arg.Is>(d => d["q"] == "something+language:\"CSharp\"")); } [Fact] @@ -1688,7 +1688,7 @@ public void TestingTheLanguageQualifier() connection.Received().Get( Arg.Is(u => u.ToString() == "search/code"), - Arg.Is>(d => d["q"] == "something+language:CSharp")); + Arg.Is>(d => d["q"] == "something+language:\"CSharp\"")); } [Fact] diff --git a/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs b/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs index bfe9f8da9c..fdbaab560f 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs @@ -68,7 +68,7 @@ public void HandlesLanguageAttributeCorrectly() request.Language = Language.CSharp; - Assert.Contains("-language:CSharp", request.MergedQualifiers()); + Assert.Contains("-language:\"CSharp\"", request.MergedQualifiers()); } [Fact] diff --git a/Octokit.Tests/Models/SearchIssuesRequestTests.cs b/Octokit.Tests/Models/SearchIssuesRequestTests.cs index 99576bfef8..caafd0ba5c 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestTests.cs @@ -156,7 +156,7 @@ public void HandlesLanguageAttributeCorrectly() Assert.DoesNotContain(request.MergedQualifiers(), x => x.Contains("language:")); request.Language = Language.CSharp; - Assert.Contains("language:CSharp", request.MergedQualifiers()); + Assert.Contains("language:\"CSharp\"", request.MergedQualifiers()); } [Fact] diff --git a/Octokit.Tests/Models/SearchRepositoryRequestTests.cs b/Octokit.Tests/Models/SearchRepositoryRequestTests.cs index c01c7288a0..ebeda46282 100644 --- a/Octokit.Tests/Models/SearchRepositoryRequestTests.cs +++ b/Octokit.Tests/Models/SearchRepositoryRequestTests.cs @@ -31,7 +31,7 @@ public void LanguageUsesParameterTranslation() { var request = new SearchRepositoriesRequest() { Language = Language.CPlusPlus }; var result = request.MergedQualifiers(); - Assert.Contains(result, x => string.Equals(x, "language:cpp")); + Assert.Contains(result, x => string.Equals(x, "language:\"cpp\"")); } } } From 71a343ee48c1b3ad9fd85c37b888a094c3a03edd Mon Sep 17 00:00:00 2001 From: Dagizmo Date: Thu, 31 Oct 2019 20:28:45 -0700 Subject: [PATCH 3/4] add missing ToParameter --- Octokit/Models/Request/SearchUsersRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Models/Request/SearchUsersRequest.cs b/Octokit/Models/Request/SearchUsersRequest.cs index 0dad61db4f..760ac87322 100644 --- a/Octokit/Models/Request/SearchUsersRequest.cs +++ b/Octokit/Models/Request/SearchUsersRequest.cs @@ -117,7 +117,7 @@ public override IReadOnlyList MergedQualifiers() if (Language != null) { - parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language)); + parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:\"{0}\"", Language.ToParameter())); } if (Created != null) From 36e5ac3a07abda2b5a57cc0a599ff03048cf92b4 Mon Sep 17 00:00:00 2001 From: Dagizmo Date: Thu, 31 Oct 2019 20:31:49 -0700 Subject: [PATCH 4/4] Modify test to add language with space --- Octokit.Tests/Clients/SearchClientTests.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 24ee618a78..a9800ca3d3 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -200,13 +200,13 @@ public void TestingTheLanguageQualifier() { var connection = Substitute.For(); var client = new SearchClient(connection); - //get users who have mostly repos where language is Ruby + //get users who have mostly repos where language is Literate Haskell var request = new SearchUsersRequest("github"); - request.Language = Language.Ruby; + request.Language = Language.LiterateHaskell; client.SearchUsers(request); connection.Received().Get( Arg.Is(u => u.ToString() == "search/users"), - Arg.Is>(d => d["q"] == "github+language:\"Ruby\"")); + Arg.Is>(d => d["q"] == "github+language:\"Literate Haskell\"")); } [Fact] @@ -462,12 +462,12 @@ public void TestingTheLangaugeQualifier() { var connection = Substitute.For(); var client = new SearchClient(connection); - //get repos who's language is Ruby + //get repos who's language is Literate Haskell var request = new SearchRepositoriesRequest("github"); - request.Language = Language.Ruby; + request.Language = Language.LiterateHaskell; client.SearchRepo(request); connection.Received().Get(Arg.Is(u => u.ToString() == "search/repositories"), - Arg.Is>(d => d["q"] == "github+language:\"ruby\"")); + Arg.Is>(d => d["q"] == "github+language:\"Literate Haskell\"")); } [Fact] @@ -986,13 +986,13 @@ public void TestingTheLanguageQualifier() var connection = Substitute.For(); var client = new SearchClient(connection); var request = new SearchIssuesRequest("something"); - request.Language = Language.CSharp; + request.Language = Language.LiterateHaskell; client.SearchIssues(request); connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), - Arg.Is>(d => d["q"] == "something+language:\"CSharp\"")); + Arg.Is>(d => d["q"] == "something+language:\"Literate Haskell\"")); } [Fact] @@ -1682,13 +1682,13 @@ public void TestingTheLanguageQualifier() var connection = Substitute.For(); var client = new SearchClient(connection); var request = new SearchCodeRequest("something"); - request.Language = Language.CSharp; + request.Language = Language.LiterateHaskell; client.SearchCode(request); connection.Received().Get( Arg.Is(u => u.ToString() == "search/code"), - Arg.Is>(d => d["q"] == "something+language:\"CSharp\"")); + Arg.Is>(d => d["q"] == "something+language:\"Literate Haskell\"")); } [Fact]