Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix for WebView Fails to Load URLs with Certain Encoded Characters #27003

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

praveenkumarkarunanithi
Copy link
Contributor

Root Cause

The root cause of the issue is the use of Uri.IsWellFormedUriString for validating URLs in the WebView control. This method applies overly strict checks, including the IsWellFormedOriginalString test, which can incorrectly reject valid URLs, especially those containing encoded characters or international characters. This leads to improper handling of certain valid URLs, causing them to be treated as relative paths instead of absolute URLs.

Description of Change

In the WebView control, the URL validation logic in MauiWebView.LoadUrl has been updated to replace Uri.IsWellFormedUriString with Uri.TryCreate. This change ensures that a wider range of valid URLs, including those with encoded and international characters, are correctly handled as absolute URLs.

Issues Fixed

Fixes #26843
Fixes #23767
Fixes #23690

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Screenshots

Before Issue Fix After Issue Fix
withoutfix withfix

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jan 8, 2025
Copy link
Contributor

Hey there @praveenkumarkarunanithi! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@praveenkumarkarunanithi
Copy link
Contributor Author

@dotnet-policy-service agree company="Syncfusion, Inc."

@vishnumenon2684 vishnumenon2684 added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jan 8, 2025
@@ -32,7 +32,7 @@ void IWebViewDelegate.LoadUrl(string? url)
_handler.CurrentNavigationEvent = WebNavigationEvent.NewPage;
}

if (url != null && !url.StartsWith('/') && !Uri.IsWellFormedUriString(url, UriKind.Absolute))
if (url != null && !url.StartsWith('/') && !Uri.TryCreate(url, UriKind.Absolute, out _))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this change be tested by a unit test? One can extract a method and test it with https://github.com/SuthiYuvaraj/maui/blob/390e4cd1c5eed59ecaf1fcd37975e7f6f5422d6d/src/Controls/tests/TestCases.HostApp/Resources/Raw/01-A%C4%9F-Sistem%20Bilgi%20G%C3%BCvenli%C4%9Fi%20Md/dotnet%20maui.pdf input. That would be faster and one can test more inputs as well.

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-webview WebView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
5 participants