Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Compatibility/Core/src/Android/Renderers/WebViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 18 additions & 1 deletion src/Core/src/Platform/Android/MauiWebView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Web;
using Android.Content;
using Android.Webkit;

Expand Down Expand Up @@ -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;
Expand Down