Fixes to uri parsing (#860)

This commit is contained in:
Matt Portune 2020-04-29 11:04:50 -04:00 committed by GitHub
parent 1d48171fd5
commit 69e0906491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 18 deletions

View file

@ -147,7 +147,7 @@ namespace Bit.Droid.Accessibility
return uri; return uri;
} }
public static string ExtractUri(string uri, AccessibilityNodeInfo addressNode, Browser browser) private static string ExtractUri(string uri, AccessibilityNodeInfo addressNode, Browser browser)
{ {
if (addressNode?.Text == null) if (addressNode?.Text == null)
{ {
@ -160,21 +160,13 @@ namespace Bit.Droid.Accessibility
uri = browser.GetUriFunction(addressNode.Text)?.Trim(); uri = browser.GetUriFunction(addressNode.Text)?.Trim();
if (uri != null && uri.Contains(".")) if (uri != null && uri.Contains("."))
{ {
if (!uri.Contains("://") && !uri.Contains(" ")) if (Uri.TryCreate(uri, UriKind.Absolute, out var uri2))
{ {
uri = string.Concat("http://", uri); return uri;
} }
else if (Build.VERSION.SdkInt <= BuildVersionCodes.KitkatWatch) if (Uri.TryCreate("http://" + uri, UriKind.Absolute, out var uri3))
{ {
var parts = uri.Split(new string[] { ". " }, StringSplitOptions.None); return string.Concat("http://", uri);
if (parts.Length > 1)
{
var urlPart = parts.FirstOrDefault(p => p.StartsWith("http"));
if (urlPart != null)
{
uri = urlPart.Trim();
}
}
} }
} }
return uri; return uri;

View file

@ -85,15 +85,14 @@ namespace Bit.Core.Utilities
{ {
return null; return null;
} }
var httpUrl = uriString.StartsWith("https://") || uriString.StartsWith("http://");
if (!httpUrl && !uriString.Contains("://") && Regex.IsMatch(uriString, TldEndingRegex))
{
uriString = "http://" + uriString;
}
if (Uri.TryCreate(uriString, UriKind.Absolute, out var uri)) if (Uri.TryCreate(uriString, UriKind.Absolute, out var uri))
{ {
return uri; return uri;
} }
if (Uri.TryCreate("http://" + uriString, UriKind.Absolute, out var uri2))
{
return uri2;
}
return null; return null;
} }