diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index 8ae982509e..b1267410cc 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -57,6 +57,20 @@ public async Task SearchForFileNameInCode() Assert.NotEmpty(repos.Items); } + [IntegrationTest] + public async Task SearchForFileNameInCodeWithoutTerm() + { + var request = new SearchCodeRequest() + { + FileName = "readme.md", + Repos = new RepositoryCollection { "octokit/octokit.net" } + }; + + var repos = await _gitHubClient.Search.SearchCode(request); + + Assert.NotEmpty(repos.Items); + } + [IntegrationTest] public async Task SearchForWordInCode() { diff --git a/Octokit/Models/Request/BaseSearchRequest.cs b/Octokit/Models/Request/BaseSearchRequest.cs index d3cff73d0c..7ff689def8 100644 --- a/Octokit/Models/Request/BaseSearchRequest.cs +++ b/Octokit/Models/Request/BaseSearchRequest.cs @@ -85,7 +85,14 @@ private string TermAndQualifiers get { var mergedParameters = string.Join("+", MergedQualifiers()); - return Term + (mergedParameters.IsNotBlank() ? "+" + mergedParameters : ""); + if (string.IsNullOrEmpty(Term)) + { + return mergedParameters; + } + else + { + return Term + (mergedParameters.IsNotBlank() ? "+" + mergedParameters : ""); + } } } diff --git a/Octokit/Models/Request/SearchCodeRequest.cs b/Octokit/Models/Request/SearchCodeRequest.cs index f5c8693dc9..4e4142310f 100644 --- a/Octokit/Models/Request/SearchCodeRequest.cs +++ b/Octokit/Models/Request/SearchCodeRequest.cs @@ -15,6 +15,14 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class SearchCodeRequest : BaseSearchRequest { + /// + /// Initializes a new instance of the class. + /// + public SearchCodeRequest() : base() + { + Repos = new RepositoryCollection(); + } + /// /// Initializes a new instance of the class. ///