-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[BlazorWebView] Fixed Allow force reload for URLs with dots in query parameters #29560
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR fixes a bug in BlazorWebView where dots in query parameters incorrectly trigger a file extension check, preventing force reloads. Key changes include using Uri.AbsolutePath for file extension validation, adding input validation for the URL, and restricting allowed schemes.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiBlazorWebView.UnitTests.csproj | New test project setup for unit tests |
src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/Extensions_Tests.cs | Comprehensive unit tests for URI handling improvements |
src/BlazorWebView/src/Maui/Properties/AssemblyInfo.cs | Added InternalsVisibleTo attribute for test project visibility |
src/BlazorWebView/src/Maui/Extensions/UriExtensions.cs | Updated extension method to check for file extensions only on the URI’s AbsolutePath |
MauiBlazorWebView.sln | Updated solution to include the new test project |
Comments suppressed due to low confidence (1)
src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/Extensions_Tests.cs:46
- [nitpick] The test method name suggests a false return value, but the assertion expects true. Consider renaming the method to reflect the correct expected outcome.
public void IsBaseOfPage_IgnoresDotInQuery_AndReturnsFalse_WhenNotBase()
Hey there @@tw4! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
[InlineData("https://example.com/test", true)] | ||
[InlineData("https://example.com/folder/subfolder/", true)] | ||
[InlineData("https://example.com/folder/file.exe", false)] | ||
public void IsBaseOfPage_HandlesVariousUris(string? uriString, bool expected) |
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.
Can include some additional cases?
[InlineData("https://subdomain.example.com/page", true)] // Subdomain
[InlineData("https://example.com/path/with/.dot/segment", true)] // Special character in path
[InlineData("https://example.com/path/with space", true)] // Space in path
[InlineData("https://example.com/path/with%20encoded%20space", true)] // URL encoded path
[InlineData("https://example.com/page?param=value¶m2=value2", true)] // Multiple query parameters
[InlineData("https://example.com/page.html", false)] // HTML file
[InlineData("HTTPS://EXAMPLE.COM/PAGE", true)] // Uppercase scheme and host
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.
Thank you for your suggestions! I have added the test cases you mentioned, and I noticed that my code was not handling subdomains correctly. After reviewing the code and extending the tests to include more subdomain scenarios, the implementation now also passes all subdomain-related test cases.
if (string.IsNullOrWhiteSpace(uriString)) | ||
return false; |
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.
I think people here prefer curly braces. There are a few other places.
if (string.IsNullOrWhiteSpace(uriString)) | |
return false; | |
if (string.IsNullOrWhiteSpace(uriString)) | |
{ | |
return false; | |
} |
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.
Thank you for the feedback.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
This PR fixes a bug in
BlazorWebView
where URLs containing dots (.
) in query parameters (e.g.,?weight=62.5
) could not be force reloaded. The issue was caused by usingPath.HasExtension(uriString)
, which mistakenly treated dots in query strings as if they were part of a file extension.❌ Before
The original logic:
This evaluates the entire URI string — including query parameters — which incorrectly caused
?value=62.5
to be treated as a file reference, breaking reload behavior.✅ After
This PR introduces a safer and more accurate approach:
Along with additional improvements:
string.IsNullOrWhiteSpace
Uri.TryCreate
to safely parse the inputhttp
andhttps
This ensures that only the actual path is evaluated for file extensions, allowing query strings to contain dots without affecting navigation or reload logic.
Issues Fixed
Fixes #25689
Cover test result

Note: @mattleibow
The previous PR might have been truly cursed 😅 — I created a new branch, rewrote the unit test project from scratch, and everything worked like a charm this time.
No issues so far, and I’m optimistic GitHub Actions will behave too! 🧙♂️✨
Also, big thanks to @mattleibow for the support and guidance — your insights helped me see things more clearly! 🙏