Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Essentials/src/Types/Shared/WebUtils.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ namespace Microsoft.Maui
static class WebUtils
{
#if !NETSTANDARD
static readonly char[] s_queryOrFragmentDelimiters = new[] { '?', '#' };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[moderate] Cross-Platform Behavioral ConsistencyQueryStringHelper.RemovePossibleQueryString in src/BlazorWebView/src/SharedSource/QueryStringHelper.cs is a parallel implementation of this same method used by all BlazorWebView handlers (Android WebKitWebViewClient.cs:119, iOS BlazorWebViewHandler.iOS.cs:318, Windows WinUIWebViewManager.cs:89, Tizen BlazorWebViewHandler.Tizen.cs:125). It still only strips ? and will fail for the same fragment-only URL scenario (e.g., MSAL OAuth redirect https://host/index.html#code=1234asdf). This PR fixes HybridWebView but leaves BlazorWebView broken under the identical scenario. The SharedSource/ origin (ASP.NET Core upstream copy) is noted, but the behavioral gap should be addressed — either by updating QueryStringHelper here (accepting upstream drift) or by opening a tracked issue before merging.


internal static string RemovePossibleQueryString(string? url)
{
if (string.IsNullOrEmpty(url))
{
return string.Empty;
}

var indexOfQueryString = url.IndexOf('?', StringComparison.Ordinal);
var indexOfQueryString = url.IndexOfAny(s_queryOrFragmentDelimiters);
return (indexOfQueryString == -1)
? url
: url.Substring(0, indexOfQueryString);
Expand Down
4 changes: 4 additions & 0 deletions src/Essentials/test/UnitTests/WebUtils_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public void ResolveRelativePath_EncodedDotDot_HandledCorrectly()
[InlineData("https://example.com", "https://example.com")]
[InlineData("https://example.com?foo=bar", "https://example.com")]
[InlineData("https://example.com/path?query=1&other=2", "https://example.com/path")]
[InlineData("https://example.com/index.html#code=abc", "https://example.com/index.html")]
[InlineData("https://example.com/path?query=1#frag", "https://example.com/path")]
[InlineData("https://example.com/path#frag?notquery", "https://example.com/path")]
[InlineData("https://0.0.0.1/index.html#code=1234asdf", "https://0.0.0.1/index.html")]
public void RemovePossibleQueryString_ReturnsExpected(string? input, string expected)
{
var result = Microsoft.Maui.WebUtils.RemovePossibleQueryString(input);
Expand Down