From b47b05489e2b06b3b498b94790c5b822fcfb0414 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 14 Jul 2016 14:20:07 -0700 Subject: [PATCH] Fix #1406 searching repos with underscore in name (#1418) --- .../Clients/SearchClientTests.cs | 29 +++++++++++++++++++ Octokit/Helpers/StringExtensions.cs | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index b1267410..009965ac 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -71,6 +71,35 @@ public class SearchClientTests Assert.NotEmpty(repos.Items); } + [IntegrationTest(Skip = "As this repository has been renamed, you cannot search for it's results.")] + public async Task SearchForFileNameInCodeWithoutTerm2() + { + var request = new SearchCodeRequest() + { + FileName = "project.json", + Repos = new RepositoryCollection { "adamcaudill/Psychson" } + }; + + + var repos = await _gitHubClient.Search.SearchCode(request); + + Assert.Empty(repos.Items); + } + + [IntegrationTest] + public async Task SearchForFileNameInCodeWithoutTermWithUnderscore() + { + var request = new SearchCodeRequest() + { + FileName = "readme.md", + Repos = new RepositoryCollection { "Cultural-Rogue/_51Wp.XinFengSDK.Demo" } + }; + + var repos = await _gitHubClient.Search.SearchCode(request); + + Assert.Empty(repos.Items); + } + [IntegrationTest] public async Task SearchForWordInCode() { diff --git a/Octokit/Helpers/StringExtensions.cs b/Octokit/Helpers/StringExtensions.cs index acff8883..50e41f36 100644 --- a/Octokit/Helpers/StringExtensions.cs +++ b/Octokit/Helpers/StringExtensions.cs @@ -122,7 +122,7 @@ namespace Octokit // the rule: // Username may only contain alphanumeric characters or single hyphens // and cannot begin or end with a hyphen - static readonly Regex nameWithOwner = new Regex("[a-z0-9.-]{1,}/[a-z0-9.-]{1,}", + static readonly Regex nameWithOwner = new Regex("[a-z0-9.-]{1,}/[a-z0-9.-_]{1,}", #if (!PORTABLE && !NETFX_CORE) RegexOptions.Compiled | #endif