Skip to content

Commit

Permalink
Allow schemeless clone URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
willibrandon committed Sep 6, 2024
1 parent e260332 commit e5216ef
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,25 +1181,32 @@ public void AddOrRemoveRepository(string accountName, IList<object> repositories
/// <remarks>If the url is not valid this method sets UrlParsingError and ShouldShowUrlError to the correct values.</remarks>
private void ValidateUriAndChangeUiIfBad(string url, out Uri uri)
{
uri = null;

// If the url isn't valid don't bother finding a provider.
if (!Uri.IsWellFormedUriString(url, UriKind.Absolute) ||
!Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri))
if (!Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri))
{
UrlParsingError = _stringResource.GetLocalized(StringResourceKey.UrlValidationBadUrl);
ShouldShowUrlError = true;
return;
}

// If user entered a relative Uri put it into a UriBuilder to turn it into an
// absolute Uri. UriBuilder prepends the https scheme
// absolute Uri. UriBuilder prepends the specified scheme.
if (!uri.IsAbsoluteUri)
{
try
{
var uriBuilder = new UriBuilder(uri.OriginalString);
uriBuilder.Port = -1;
var uriBuilder = new UriBuilder(Uri.UriSchemeHttps, uri.OriginalString)
{
Port = -1,
};

if (!Uri.IsWellFormedUriString(uriBuilder.Uri.OriginalString, UriKind.Absolute))
{
UrlParsingError = _stringResource.GetLocalized(StringResourceKey.UrlValidationBadUrl);
ShouldShowUrlError = true;
return;
}

uri = uriBuilder.Uri;
}
catch (Exception e)
Expand Down

0 comments on commit e5216ef

Please sign in to comment.