Skip to content

BlazorWebView: ignore query‑string dots in IsBaseOfPage #29452

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

Closed
wants to merge 2 commits into from

Conversation

tw4
Copy link

@tw4 tw4 commented May 12, 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

BlazorWebView’s force reload logic misidentified query‑string dots (?weight=62.5, etc.) as file‑extension dots, so the page was treated as a file and an empty “There is no content at url” screen appeared.
UriExtensions.IsBaseOfPage now calls Path.HasExtension(uri.AbsolutePath), evaluating only the path (AbsolutePath) segment, so dots in the query or fragment no longer trigger the false file‑extension check.

Fixes #25689

@Copilot Copilot AI review requested due to automatic review settings May 12, 2025 19:11
@tw4 tw4 requested a review from a team as a code owner May 12, 2025 19:11
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 an issue in BlazorWebView where query‑string dots were incorrectly interpreted as file‑extension dots, leading to a faulty file-loading behavior. The changes update the UriExtensions.IsBaseOfPage method to evaluate the AbsolutePath of the URI instead of the entire URI string.

  • Update null/whitespace check and URI parsing.
  • Change file extension check from the entire URI to its AbsolutePath segment.

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label May 12, 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.

@tw4
Copy link
Author

tw4 commented May 12, 2025

@dotnet-policy-service agree

@tw4 tw4 requested a review from Copilot May 13, 2025 10:36
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 an issue in BlazorWebView where query‑string dots were mistakenly interpreted as file‑extension dots, preventing proper page loading.

  • Updated IsBaseOfPage in UriExtensions to use the AbsolutePath for extension check.
  • Added guard clauses for null/whitespace and validated the URI scheme before checking for file extensions.
Comments suppressed due to low confidence (1)

src/BlazorWebView/src/Maui/Extensions/UriExtensions.cs:19

  • Ensure that test cases in TestCases.HostApp and TestCases.Shared.Tests cover scenarios with query-string dots so that the updated logic in IsBaseOfPage behaves as expected.
if (Path.HasExtension(uri.AbsolutePath))

Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, but please add some unit tests of common URLs that this will fix and add the corner cases that this may trip up on.

@tw4
Copy link
Author

tw4 commented May 15, 2025

Thank you for your feedback.

I tried to create the unit tests directly within the Maui project, but I ran into a few issues. Because the class is internal and due to some SDK-related errors, I wasn’t able to write the tests inside the project itself. Instead, I created a separate project to write the unit tests and verify the fix, although I realize this isn’t the ideal approach.

If you prefer, you can close this PR. I haven’t been able to set up proper unit testing within the Maui project yet. Still, I wanted to share my progress and make sure that the main bug is covered by tests—even though the tests are currently in an external project.

Thank you for your understanding.

repo:https://github.com/tw4/MauiUnitTest

Screen.Recording.2025-05-15.at.21.52.05.mov

@tw4 tw4 requested a review from mattleibow May 15, 2025 19:04
@mattleibow

This comment was marked as off-topic.

@mattleibow
Copy link
Member

mattleibow commented May 15, 2025

I see, maybe add an the internals visible attribute in here for the device tests: https://github.com/dotnet/maui/blob/342b2730b05bbf3559ee6a167efa4ea135dff375/src/BlazorWebView/src/Maui/Properties/AssemblyInfo.cs

[assembly: InternalsVisibleTo("Microsoft.Maui.MauiBlazorWebView.DeviceTests")]

It would have been ideal to have a unit tests project that runs faster to test things that don't need to be on device, but we don't have that yet so a device test is fine.

@mattleibow

This comment was marked as off-topic.

@mattleibow

This comment was marked as off-topic.

@mattleibow

This comment was marked as off-topic.

@mattleibow

This comment was marked as off-topic.

@mattleibow mattleibow closed this May 15, 2025
@mattleibow mattleibow reopened this May 15, 2025
@bhavanesh2001

This comment was marked as off-topic.

@mattleibow

This comment was marked as off-topic.

@jsuarezruiz jsuarezruiz added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label May 16, 2025
@tw4 tw4 closed this May 16, 2025
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.

4 participants