maui icon indicating copy to clipboard operation
maui copied to clipboard

[Android] Encoding webview's source

Open kubaflo opened this issue 1 year ago • 8 comments

Issues Fixed

Fixes https://github.com/dotnet/maui/issues/23767 Fixes https://github.com/dotnet/maui/issues/23690

Before After

kubaflo avatar Aug 04 '24 12:08 kubaflo

This just fixes the spaces, there is another issue for square brackets. Should we just use the UriEncode method to catch it all?

jfversluis avatar Aug 04 '24 12:08 jfversluis

@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 :/

kubaflo avatar Aug 04 '24 12:08 kubaflo

Oh yeah that makes sense. Hmmm I do wonder why this worked in Xamarin.Forms though and not here. Same with #23690

jfversluis avatar Aug 06 '24 08:08 jfversluis

@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;
} 

void LoadUrl(string url, bool fireNavigatingCanceled)

kubaflo avatar Aug 06 '24 09:08 kubaflo

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 };

David-Ernstsson avatar Oct 07 '24 11:10 David-Ernstsson

/azp run

jsuarezruiz avatar Oct 23 '24 09:10 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 23 '24 09:10 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Nov 26 '24 10:11 azure-pipelines[bot]

Closing in favour of https://github.com/dotnet/maui/pull/27003

kubaflo avatar Mar 12 '25 14:03 kubaflo