diff --git a/src/Compatibility/Core/src/Android/Renderers/WebViewRenderer.cs b/src/Compatibility/Core/src/Android/Renderers/WebViewRenderer.cs index 82b35b7a1cc1..b0097aa8c767 100644 --- a/src/Compatibility/Core/src/Android/Renderers/WebViewRenderer.cs +++ b/src/Compatibility/Core/src/Android/Renderers/WebViewRenderer.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Android.Content; using Android.Webkit; +using System.Web; using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Controls.Platform; using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific; @@ -48,7 +49,24 @@ void LoadUrl(string url, bool fireNavigatingCanceled) if (!fireNavigatingCanceled || !SendNavigatingCanceled(url)) { _eventState = WebNavigationEvent.NewPage; - if (url != null && !url.StartsWith('/') && !Uri.IsWellFormedUriString(url, UriKind.Absolute)) + + string? encodedUrl = url; + if (!string.IsNullOrEmpty(encodedUrl)) + { + int questionMarkIndex = encodedUrl.IndexOf('?', StringComparison.InvariantCulture); + + if (questionMarkIndex != -1) + { + string baseUrl = encodedUrl.Substring(0, questionMarkIndex + 1); + string queryString = encodedUrl.Substring(questionMarkIndex + 1); + + // URI encode the part after the '?' + string encodedPart = HttpUtility.UrlEncode(queryString); + encodedUrl = baseUrl + encodedPart; + } + } + + if (url != null && !url.StartsWith('/') && !Uri.IsWellFormedUriString(encodedUrl, UriKind.Absolute)) { // URLs like "index.html" can't possibly load, so try "file:///android_asset/index.html" url = AssetBaseUrl + url; diff --git a/src/Core/src/Platform/Android/MauiWebView.cs b/src/Core/src/Platform/Android/MauiWebView.cs index 807e7d705e83..10d9470f4f4f 100644 --- a/src/Core/src/Platform/Android/MauiWebView.cs +++ b/src/Core/src/Platform/Android/MauiWebView.cs @@ -1,4 +1,5 @@ using System; +using System.Web; using Android.Content; using Android.Webkit; @@ -32,7 +33,23 @@ void IWebViewDelegate.LoadUrl(string? url) _handler.CurrentNavigationEvent = WebNavigationEvent.NewPage; } - if (url != null && !url.StartsWith('/') && !Uri.IsWellFormedUriString(url, UriKind.Absolute)) + string? encodedUrl = url; + if (!string.IsNullOrEmpty(encodedUrl)) + { + int questionMarkIndex = encodedUrl.IndexOf('?', StringComparison.InvariantCulture); + + if (questionMarkIndex != -1) + { + string baseUrl = encodedUrl.Substring(0, questionMarkIndex + 1); + string queryString = encodedUrl.Substring(questionMarkIndex + 1); + + // URI encode the part after the '?' + string encodedPart = HttpUtility.UrlEncode(queryString); + encodedUrl = baseUrl + encodedPart; + } + } + + if (url != null && !url.StartsWith('/') && !Uri.IsWellFormedUriString(encodedUrl, UriKind.Absolute)) { // URLs like "index.html" can't possibly load, so try "file:///android_asset/index.html" url = AssetBaseUrl + url;