Skip to content

[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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tw4
Copy link

@tw4 tw4 commented May 16, 2025

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 using Path.HasExtension(uriString), which mistakenly treated dots in query strings as if they were part of a file extension.


❌ Before

The original logic:

if (Path.HasExtension(uriString))
    return false;

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:

if (Path.HasExtension(uri.AbsolutePath))
    return false;

Along with additional improvements:

  • Validates input with string.IsNullOrWhiteSpace
  • Uses Uri.TryCreate to safely parse the input
  • Restricts allowed schemes to http and https

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
Screenshot 2025-05-16 at 22 54 41


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! 🙏

@Copilot Copilot AI review requested due to automatic review settings May 16, 2025 20:01
@tw4 tw4 requested review from a team as code owners May 16, 2025 20:01
@tw4 tw4 requested review from jfversluis and jsuarezruiz May 16, 2025 20:01
Copy link
Contributor

@Copilot Copilot AI left a 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()

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

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.

@jsuarezruiz jsuarezruiz added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label May 19, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

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)
Copy link
Contributor

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&param2=value2", true)]  // Multiple query parameters
[InlineData("https://example.com/page.html", false)]  // HTML file
[InlineData("HTTPS://EXAMPLE.COM/PAGE", true)]  // Uppercase scheme and host

Copy link
Author

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.

@tw4 tw4 requested a review from jsuarezruiz May 19, 2025 07:15
Comment on lines 10 to 11
if (string.IsNullOrWhiteSpace(uriString))
return false;
Copy link
Contributor

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.

Suggested change
if (string.IsNullOrWhiteSpace(uriString))
return false;
if (string.IsNullOrWhiteSpace(uriString))
{
return false;
}

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView community ✨ Community Contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blazor Hybrid Webview cannot be force reloaded for urls containing query parameters with a dot (.)
3 participants