[Android] Encoding webview's source
Issues Fixed
Fixes https://github.com/dotnet/maui/issues/23767 Fixes https://github.com/dotnet/maui/issues/23690
| Before | After |
|---|---|
This just fixes the spaces, there is another issue for square brackets. Should we just use the UriEncode method to catch it all?
@jfversluis
The problem with Uri encode: string? encodedUrl = HttpUtility.UrlEncode(url);
https://www.google.com/search?q=test 123 becomes https%3a%2f%2fwww.google.com%2fsearch%3fq%3dtest+123 and Uri.IsWellFormedUriString validates it as a bad URL :/
Oh yeah that makes sense. Hmmm I do wonder why this worked in Xamarin.Forms though and not here. Same with #23690
@jfversluis It looks like Xamarin didn't have this logic:
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;
}
Any progress on this? Not sure if I have same problem since a single bracket or space works fine when escaped.
HOWEVER using a space AND a german special character creates error shown above. See sample code:
var webView = new WebView();
var text = Uri.EscapeDataString("sehr schön");
var source = $"https://translate.google.com/?sl=de&tl=en&op=translate&text={text}";
webView.Source = new UrlWebViewSource { Url = source };
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
Closing in favour of https://github.com/dotnet/maui/pull/27003