From b4139d46da98b32939495a1e3bde304ab20a3f8c Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Fri, 17 Jul 2015 07:53:18 +0930 Subject: [PATCH] rework the rules --- Octokit.Tests/Clients/SearchClientTests.cs | 31 ++++++++++++++++------ Octokit/Helpers/StringExtensions.cs | 9 ++++--- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index ed59dbbe5d..39570b0986 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1159,6 +1159,24 @@ public void TestingTheRepoQualifier() Arg.Is>(d => d["q"] == "something+repo:octokit/octokit.net")); } + [Fact] + public async Task ErrorOccursWhenSpecifyingInvalidFormatForRepos() + { + var connection = Substitute.For(); + var client = new SearchClient(connection); + + var request = new SearchIssuesRequest("windows"); + request.Repos = new Collection { + "haha-business" + }; + + request.SortField = IssueSearchSort.Created; + request.Order = SortDirection.Descending; + + await Assert.ThrowsAsync( + async () => await client.SearchIssues(request)); + } + [Fact] public void TestingTheRepoAndUserAndLabelQualifier() { @@ -1450,7 +1468,7 @@ public void TestingTheRepoQualifier() connection.Received().Get( Arg.Is(u => u.ToString() == "search/code"), - Arg.Is>(d => d["q"] == "something+repo:octokit.net")); + Arg.Is>(d => d["q"] == "something+repo:octokit/octokit.net")); } [Fact] @@ -1482,7 +1500,7 @@ public void TestingTheRepoAndPathAndExtensionQualifiers() connection.Received().Get( Arg.Is(u => u.ToString() == "search/code"), Arg.Is>(d => - d["q"] == "something+path:tools/FAKE.core+extension:fs+repo:octokit.net")); + d["q"] == "something+path:tools/FAKE.core+extension:fs+repo:octokit/octokit.net")); } [Fact] @@ -1491,19 +1509,16 @@ public async Task ErrorOccursWhenSpecifyingInvalidFormatForRepos() var connection = Substitute.For(); var client = new SearchClient(connection); - var request = new SearchIssuesRequest("windows"); + var request = new SearchCodeRequest("windows"); request.Repos = new Collection { "haha-business" }; - request.SortField = IssueSearchSort.Created; request.Order = SortDirection.Descending; - await Assert.ThrowsAsync( - async () => await client.SearchIssues(request)); + await Assert.ThrowsAsync( + async () => await client.SearchCode(request)); } - - } } } diff --git a/Octokit/Helpers/StringExtensions.cs b/Octokit/Helpers/StringExtensions.cs index 33008b3e15..670eddf244 100644 --- a/Octokit/Helpers/StringExtensions.cs +++ b/Octokit/Helpers/StringExtensions.cs @@ -102,11 +102,14 @@ static IEnumerable SplitUpperCase(this string source) yield return new String(letters, wordStartIndex, letters.Length - wordStartIndex); } - static Regex nameWithOwner = new Regex("[a-zA-Z.]{1,}/[a-zA-Z.]{1,}" + // 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,}", #if (!PORTABLE && !NETFX_CORE) -, RegexOptions.Compiled + RegexOptions.Compiled | #endif -); + RegexOptions.IgnoreCase); internal static bool IsNameWithOwnerFormat(this string input) {