-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix for WebView Fails to Load URLs with Certain Encoded Characters #27003
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
Conversation
|
@dotnet-policy-service agree company="Syncfusion, Inc." |
|
/azp run |
This comment was marked as outdated.
This comment was marked as outdated.
|
/azp run |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
jfversluis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build error
/Users/builder/azdo/_work/3/s/src/Core/src/Platform/WebViewHelper.cs(9,32): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/Users/builder/azdo/_work/3/s/src/Core/src/Core.csproj::TargetFramework=netstandard2.0]
IMHO we hit #27003 (comment) |
|
@praveenkumarkarunanithi IMHO it was OK as it was, the only thing that was necessary was to do: internal static class WebViewHelper
{
internal static bool IsRelativeUrl(string url)
{
// return !url.StartsWith('/') && !Uri.TryCreate(url, UriKind.Absolute, out _);
return !url.StartsWith("/", StringComparison.Ordinal) && !Uri.TryCreate(url, UriKind.Absolute, out _);
}
} |
@MartyIX, @jfversluis This fix is specific to the Android platform, creating a unit test would require significant changes to access the method within the unit test class for android. Instead, we added a UI test with assert validation to ensure the fix works across all platforms. This approach provides comprehensive coverage and validation without extensive refactoring. Let us know if you have further thoughts! |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
/azp run |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
PureWeen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebViewShouldLoadEncodedUrl is failing
jsuarezruiz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
jsuarezruiz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the tests are passing although I would review the use of VerifyInternetConnectivity.
Uri.IsWellFormedUriString in some scenarios, like including escaped characters, might cause to return false even for a valid URI. Uri.TryCreate is a safer and more robust choice because it both validates the URI and creates the object for further use if needed. In this case, we are creating the Uri object and not using it. Although it is not critical in performance and improves robustness.
| /// Checks if internet connection is available by making an HTTP request | ||
| /// </summary> | ||
| /// <returns>True if internet connection is available</returns> | ||
| public static async Task<bool> HasInternetConnection() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? Can't you use the VerifyInternetConnectivity(); existing method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz , The existing method (VerifyInternetConnectivity) is added in the UITest project, but since this is a different project (Device Test), I have added the method separately here.
@jsuarezruiz , Thanks for the feedback! You're correct—I'm currently discarding the created Uri object (out _). The main reason for using Uri.TryCreate here is its improved accuracy in validating URLs containing escaped characters, which Uri.IsWellFormedUriString incorrectly rejects. |
|
@PureWeen How many months do we have to wait till this essential bugfix will be merged? This thing is basically done and works as expected (Thanks to @praveenkumarkarunanithi). |
…racters (#27003) * Fix code and test case commit * test case code updated * removed ui tests as it used user name included url * updated unit test case * updated fix and unit test case * updated the new class access specifier. * Removed unit test descriptions * Fix updated * updated the unit test case * Reverted unit test and added UI test case * updated test case description * updating ui test case with ignore windows comment * updated windows issue url * updating test case with comments. * updated the test case as device test * removed ui test * Fix build error * updated device test with conditional skip code * updating test case with internet connectivity checks. --------- Co-authored-by: Gerald Versluis <gerald@verslu.is>
…racters (#27003) * Fix code and test case commit * test case code updated * removed ui tests as it used user name included url * updated unit test case * updated fix and unit test case * updated the new class access specifier. * Removed unit test descriptions * Fix updated * updated the unit test case * Reverted unit test and added UI test case * updated test case description * updating ui test case with ignore windows comment * updated windows issue url * updating test case with comments. * updated the test case as device test * removed ui test * Fix build error * updated device test with conditional skip code * updating test case with internet connectivity checks. --------- Co-authored-by: Gerald Versluis <gerald@verslu.is>
…racters (#27003) * Fix code and test case commit * test case code updated * removed ui tests as it used user name included url * updated unit test case * updated fix and unit test case * updated the new class access specifier. * Removed unit test descriptions * Fix updated * updated the unit test case * Reverted unit test and added UI test case * updated test case description * updating ui test case with ignore windows comment * updated windows issue url * updating test case with comments. * updated the test case as device test * removed ui test * Fix build error * updated device test with conditional skip code * updating test case with internet connectivity checks. --------- Co-authored-by: Gerald Versluis <gerald@verslu.is>
…racters (dotnet#27003) * Fix code and test case commit * test case code updated * removed ui tests as it used user name included url * updated unit test case * updated fix and unit test case * updated the new class access specifier. * Removed unit test descriptions * Fix updated * updated the unit test case * Reverted unit test and added UI test case * updated test case description * updating ui test case with ignore windows comment * updated windows issue url * updating test case with comments. * updated the test case as device test * removed ui test * Fix build error * updated device test with conditional skip code * updating test case with internet connectivity checks. --------- Co-authored-by: Gerald Versluis <gerald@verslu.is>

Root Cause
The root cause of the issue is the use of
Uri.IsWellFormedUriStringfor validating URLs in the WebView control. This method applies overly strict checks, including theIsWellFormedOriginalStringtest, 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.LoadUrlhas been updated to replaceUri.IsWellFormedUriStringwithUri.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
Closes #24002
Tested the behaviour in the following platforms
Test case failing on windows. for more information: #27425
Screenshots