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

Commit f09fb86

Browse files
committed
ToWebUrl needs to normalize URLs
1 parent 4f726d9 commit f09fb86

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/GitHub.Exports/Primitives/UriString.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ bool ParseScpSyntax(string scpString)
121121

122122
public Uri ToWebUri()
123123
{
124-
if (url == null || (url.Scheme != Uri.UriSchemeHttp && url.Scheme != Uri.UriSchemeHttps))
124+
var scheme = url != null && IsHypertextTransferProtocol
125+
? url.Scheme
126+
: Uri.UriSchemeHttps;
127+
128+
return new UriBuilder
125129
{
126-
return new UriBuilder
127-
{
128-
Scheme = Uri.UriSchemeHttps,
129-
Host = Host,
130-
Path = NameWithOwner,
131-
Port = url?.Port == 80
132-
? -1
133-
: (url?.Port ?? -1)
134-
}.Uri;
135-
}
136-
return url;
130+
Scheme = scheme,
131+
Host = Host,
132+
Path = NameWithOwner,
133+
Port = url?.Port == 80
134+
? -1
135+
: (url?.Port ?? -1)
136+
}.Uri;
137137
}
138138

139139
/// <summary>

src/UnitTests/GitHub.Primitives/UriStringTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public class TheToUriMethod
165165
[InlineData("http://example.com/", "http://example.com/")]
166166
[InlineData("http://[email protected]/foo/bar", "http://example.com/foo/bar")]
167167
[InlineData("https://github.com/github/Windows", "https://github.com/github/Windows")]
168+
[InlineData("https://github.com/github/Windows.git", "https://github.com/github/Windows")]
169+
[InlineData("https://[email protected]/github/Windows.git", "https://github.com/github/Windows")]
168170
[InlineData("http://example.com:4000/github/Windows", "http://example.com:4000/github/Windows")]
169171
[InlineData("[email protected]:github/Windows.git", "https://192.168.1.2/github/Windows")]
170172
[InlineData("[email protected]:org/repo.git", "https://example.com/org/repo")]

src/UnitTests/GitHub.VisualStudio/TeamExplorer/Home/GraphsNavigationItemTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class GraphsNavigationItemTests
1010
public class TheExecuteMethod
1111
{
1212
[Theory]
13+
[InlineData("https://github.com/foo/bar.git", "https://github.com/foo/bar/graphs")]
14+
[InlineData("https://[email protected]/foo/bar.git", "https://github.com/foo/bar/graphs")]
1315
[InlineData("https://github.com/foo/bar", "https://github.com/foo/bar/graphs")]
1416
[InlineData("https://github.com/foo/bar/", "https://github.com/foo/bar/graphs")]
1517
public void BrowsesToTheCorrectURL(string origin, string expectedUrl)

0 commit comments

Comments
 (0)