Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 8a6374e

Browse files
authored
Merge pull request #2351 from github/fixes/2350-invalid-space-open-from-github
Ignore whitespace in Open from GitHub search box
2 parents 435a838 + 7a089ec commit 8a6374e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/GitHub.App/ViewModels/Dialog/Clone/RepositorySelectViewModel.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,23 @@ async Task LoadItems(bool refresh)
186186

187187
bool FilterItem(object obj)
188188
{
189-
if (obj is IRepositoryItemViewModel item && !string.IsNullOrWhiteSpace(Filter))
189+
var trimedFilter = Filter?.Trim();
190+
if (obj is IRepositoryItemViewModel item && !string.IsNullOrEmpty(trimedFilter))
190191
{
191-
if (new UriString(Filter).IsHypertextTransferProtocol)
192+
if (new UriString(trimedFilter).IsHypertextTransferProtocol)
192193
{
193194
var urlString = item.Url.ToString();
194195
var urlStringWithGit = urlString + ".git";
195196
var urlStringWithSlash = urlString + "/";
196197
return
197-
urlString.Contains(Filter, StringComparison.OrdinalIgnoreCase) ||
198-
urlStringWithGit.Contains(Filter, StringComparison.OrdinalIgnoreCase) ||
199-
urlStringWithSlash.Contains(Filter, StringComparison.OrdinalIgnoreCase);
198+
urlString.Contains(trimedFilter, StringComparison.OrdinalIgnoreCase) ||
199+
urlStringWithGit.Contains(trimedFilter, StringComparison.OrdinalIgnoreCase) ||
200+
urlStringWithSlash.Contains(trimedFilter, StringComparison.OrdinalIgnoreCase);
200201
}
201202
else
202203
{
203204
return
204-
item.Caption.Contains(Filter, StringComparison.CurrentCultureIgnoreCase);
205+
item.Caption.Contains(trimedFilter, StringComparison.CurrentCultureIgnoreCase);
205206
}
206207
}
207208

test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositorySelectViewModelTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class TheFilterProperty
1818
[TestCase("", "owner", "name", "https://github.com/owner/name", 1)]
1919
[TestCase("owner", "owner", "name", "https://github.com/owner/name", 1)]
2020
[TestCase("name", "owner", "name", "https://github.com/owner/name", 1)]
21+
[TestCase(" name", "owner", "name", "https://github.com/owner/name", 1, Description = "Ignore whitespace before filter")]
22+
[TestCase("name ", "owner", "name", "https://github.com/owner/name", 1, Description = "Ignore whitespace after filter")]
23+
[TestCase("https://github.com/owner/name ", "owner", "name", "https://github.com/owner/name", 1, Description = "Ignore whitespace in URL filter")]
2124
[TestCase("owner/name", "owner", "name", "https://github.com/owner/name", 1)]
2225
[TestCase("OWNER/NAME", "owner", "name", "https://github.com/owner/name", 1)]
2326
[TestCase("https://github.com/owner/name", "owner", "name", "https://github.com/owner/name", 1)]

0 commit comments

Comments
 (0)