From 69e0906491839081e47125eff9aba93be1340ed6 Mon Sep 17 00:00:00 2001 From: Matt Portune <59324545+mportune-bw@users.noreply.github.com> Date: Wed, 29 Apr 2020 11:04:50 -0400 Subject: [PATCH] Fixes to uri parsing (#860) --- .../Accessibility/AccessibilityHelpers.cs | 18 +++++------------- src/Core/Utilities/CoreHelpers.cs | 9 ++++----- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/Android/Accessibility/AccessibilityHelpers.cs b/src/Android/Accessibility/AccessibilityHelpers.cs index cbcad78b3..ce6142706 100644 --- a/src/Android/Accessibility/AccessibilityHelpers.cs +++ b/src/Android/Accessibility/AccessibilityHelpers.cs @@ -147,7 +147,7 @@ namespace Bit.Droid.Accessibility 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) { @@ -160,21 +160,13 @@ namespace Bit.Droid.Accessibility uri = browser.GetUriFunction(addressNode.Text)?.Trim(); 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); - if (parts.Length > 1) - { - var urlPart = parts.FirstOrDefault(p => p.StartsWith("http")); - if (urlPart != null) - { - uri = urlPart.Trim(); - } - } + return string.Concat("http://", uri); } } return uri; diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs index 562733867..d8f1e2525 100644 --- a/src/Core/Utilities/CoreHelpers.cs +++ b/src/Core/Utilities/CoreHelpers.cs @@ -85,15 +85,14 @@ namespace Bit.Core.Utilities { 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)) { return uri; } + if (Uri.TryCreate("http://" + uriString, UriKind.Absolute, out var uri2)) + { + return uri2; + } return null; }