Skip to content

[Android] Encoding webview's source#24002

Closed
kubaflo wants to merge 2 commits intodotnet:mainfrom
kubaflo:fix-23767
Closed

[Android] Encoding webview's source#24002
kubaflo wants to merge 2 commits intodotnet:mainfrom
kubaflo:fix-23767

Conversation

@kubaflo
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo commented Aug 4, 2024

Issues Fixed

Fixes #23767
Fixes #23690

Before After
Screen.Recording.2024-08-04.at.14.06.51.mov
Screen.Recording.2024-08-04.at.14.04.00.mov

@jfversluis
Copy link
Copy Markdown
Member

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

@kubaflo
Copy link
Copy Markdown
Contributor Author

kubaflo commented Aug 4, 2024

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

@jfversluis
Copy link
Copy Markdown
Member

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

@kubaflo
Copy link
Copy Markdown
Contributor Author

kubaflo commented Aug 6, 2024

@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 kubaflo changed the title [Android] Space character in Webview's Source [Android] Encoding webview's source Sep 5, 2024
@David-Ernstsson
Copy link
Copy Markdown

David-Ernstsson commented Oct 7, 2024

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

@jsuarezruiz
Copy link
Copy Markdown
Contributor

jsuarezruiz commented Oct 23, 2024

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@kubaflo
Copy link
Copy Markdown
Contributor Author

kubaflo commented Mar 12, 2025

Closing in favour of #27003

@kubaflo kubaflo closed this Mar 12, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

5 participants