Skip to content

Commit

Permalink
rework the rules
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftkey committed Jul 16, 2015
1 parent 51eab3f commit b4139d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
31 changes: 23 additions & 8 deletions Octokit.Tests/Clients/SearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,24 @@ public void TestingTheRepoQualifier()
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+repo:octokit/octokit.net"));
}

[Fact]
public async Task ErrorOccursWhenSpecifyingInvalidFormatForRepos()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);

var request = new SearchIssuesRequest("windows");
request.Repos = new Collection<string> {
"haha-business"
};

request.SortField = IssueSearchSort.Created;
request.Order = SortDirection.Descending;

await Assert.ThrowsAsync<RepositoryFormatException>(
async () => await client.SearchIssues(request));
}

[Fact]
public void TestingTheRepoAndUserAndLabelQualifier()
{
Expand Down Expand Up @@ -1450,7 +1468,7 @@ public void TestingTheRepoQualifier()

connection.Received().Get<SearchCodeResult>(
Arg.Is<Uri>(u => u.ToString() == "search/code"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+repo:octokit.net"));
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+repo:octokit/octokit.net"));
}

[Fact]
Expand Down Expand Up @@ -1482,7 +1500,7 @@ public void TestingTheRepoAndPathAndExtensionQualifiers()
connection.Received().Get<SearchCodeResult>(
Arg.Is<Uri>(u => u.ToString() == "search/code"),
Arg.Is<Dictionary<string, string>>(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]
Expand All @@ -1491,19 +1509,16 @@ public async Task ErrorOccursWhenSpecifyingInvalidFormatForRepos()
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);

var request = new SearchIssuesRequest("windows");
var request = new SearchCodeRequest("windows");
request.Repos = new Collection<string> {
"haha-business"
};

request.SortField = IssueSearchSort.Created;
request.Order = SortDirection.Descending;

await Assert.ThrowsAsync<ArgumentException>(
async () => await client.SearchIssues(request));
await Assert.ThrowsAsync<RepositoryFormatException>(
async () => await client.SearchCode(request));
}


}
}
}
9 changes: 6 additions & 3 deletions Octokit/Helpers/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ static IEnumerable<string> 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)
{
Expand Down

0 comments on commit b4139d4

Please sign in to comment.