-
Notifications
You must be signed in to change notification settings - Fork 2k
[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
Changes from 10 commits
74bb09d
b80e38c
c69bd8c
2e207aa
2484122
b34a8e2
1ceccae
2d329b5
51ebb96
85074a0
a856301
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,27 @@ | ||
| using System; | ||
| using System.IO; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.WebView.Maui | ||
| namespace Microsoft.AspNetCore.Components.WebView.Maui; | ||
|
|
||
| internal static class UriExtensions | ||
| { | ||
| internal static class UriExtensions | ||
| internal static bool IsBaseOfPage(this Uri baseUri, string? uriString) | ||
| { | ||
| internal static bool IsBaseOfPage(this Uri baseUri, string? uriString) | ||
| if (string.IsNullOrWhiteSpace(uriString)) | ||
| { | ||
| if (Path.HasExtension(uriString)) | ||
| { | ||
| // If the path ends in a file extension, it's not referring to a page. | ||
| return false; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| var uri = new Uri(uriString!); | ||
| return baseUri.IsBaseOf(uri); | ||
| if (!Uri.TryCreate(uriString, UriKind.Absolute, out var uri)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (Path.HasExtension(uri.GetComponents(UriComponents.Path, UriFormat.Unescaped))) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return baseUri.IsBaseOf(uri); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Controls.Internals; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
|
|
||
| [assembly: Preserve] | ||
|
|
||
| [assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/2021/maui", "Microsoft.AspNetCore.Components.WebView.Maui")] | ||
| [assembly: InternalsVisibleTo("Microsoft.Maui.MauiBlazorWebView.UnitTests")] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(_MauiDotNetTfm)</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <RootNamespace>Microsoft.Maui.MauiBlazorWebView.UnitTests</RootNamespace> | ||
| <AssemblyName>Microsoft.Maui.MauiBlazorWebView.UnitTests</AssemblyName> | ||
| <Nullable>enable</Nullable> | ||
| <IsPackable>false</IsPackable> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ The new BlazorWebView unit tests are added as a project/solution entry, but they are not wired into the repo's unit-test execution lists. |
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.collector" Version="$(CoverletCollectorPackageVersion)" /> | ||
| <PackageReference Include="xunit" Version="$(XunitPackageVersion)" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="Xunit" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Maui\Microsoft.AspNetCore.Components.WebView.Maui.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,106 @@ | ||||||||||||||
| using Microsoft.AspNetCore.Components.WebView.Maui; | ||||||||||||||
|
|
||||||||||||||
| namespace Microsoft.Maui.MauiBlazorWebView.UnitTests; | ||||||||||||||
|
|
||||||||||||||
| public class UriExtensions_Tests | ||||||||||||||
| { | ||||||||||||||
| private readonly Uri _baseUri = new("https://example.com/"); | ||||||||||||||
|
|
||||||||||||||
| [Theory] | ||||||||||||||
| [InlineData("https://example.com/page", true)] | ||||||||||||||
| [InlineData("page/subpage", false)] | ||||||||||||||
| [InlineData("this is not a uri!", false)] | ||||||||||||||
| [InlineData("https://example.com/", true)] | ||||||||||||||
| [InlineData("https://example.com/page/", true)] | ||||||||||||||
| [InlineData("https://example.com/page?weight=62.5", true)] | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [moderate] Regression Prevention — The regression case exercises |
||||||||||||||
| [InlineData("https://example.com/page#section.1", true)] | ||||||||||||||
| [InlineData("https://example.com/file.txt", false)] | ||||||||||||||
| [InlineData("https://example.com/page.json?foo=bar", false)] | ||||||||||||||
| [InlineData("ftp://example.com/page", false)] | ||||||||||||||
| [InlineData("/relative/path", false)] | ||||||||||||||
| [InlineData("", false)] | ||||||||||||||
| [InlineData(null, false)] | ||||||||||||||
| [InlineData("https://example.com/test", true)] | ||||||||||||||
| [InlineData("https://example.com/folder/subfolder/", true)] | ||||||||||||||
| [InlineData("https://example.com/folder/file.exe", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/page", false)] | ||||||||||||||
| [InlineData("https://example.com/path/with/.dot/segment", true)] | ||||||||||||||
| [InlineData("https://example.com/path/with space", true)] | ||||||||||||||
| [InlineData("https://example.com/path/with%20encoded%20space", true)] | ||||||||||||||
| [InlineData("https://example.com/page?param=value¶m2=value2", true)] | ||||||||||||||
| [InlineData("https://example.com/page.html", false)] | ||||||||||||||
| [InlineData("HTTPS://EXAMPLE.COM/PAGE", true)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/page/", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/page?weight=62.5", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/page#section.1", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/file.txt", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/page.json?foo=bar", false)] | ||||||||||||||
| [InlineData("ftp://subdomain.example.com/page", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/test", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/folder/subfolder/", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/folder/file.exe", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/path/with/.dot/segment", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/path/with space", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/path/with%20encoded%20space", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/page?param=value¶m2=value2", false)] | ||||||||||||||
| [InlineData("https://subdomain.example.com/page.html", false)] | ||||||||||||||
| [InlineData("HTTPS://SUBDOMAIN.EXAMPLE.COM/PAGE", false)] | ||||||||||||||
| public void IsBaseOfPage_HandlesVariousUris(string? uriString, bool expected) | ||||||||||||||
|
tw4 marked this conversation as resolved.
|
||||||||||||||
| { | ||||||||||||||
| var result = _baseUri.IsBaseOfPage(uriString); | ||||||||||||||
| Assert.Equal(expected, result); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| [Fact] | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Regression Prevention — Test duplication — Five of the six standalone
Consider removing these duplicates and consolidating only the non-redundant case ( |
||||||||||||||
| public void IsBaseOfPage_ReturnsFalse_WhenPathHasFileExtension() | ||||||||||||||
| { | ||||||||||||||
| var uriWithExtension = "https://example.com/assets/image.png"; | ||||||||||||||
| Assert.False(_baseUri.IsBaseOfPage(uriWithExtension)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| [Fact] | ||||||||||||||
| public void IsBaseOfPage_ReturnsTrue_WhenUriIsBaseItself() | ||||||||||||||
| { | ||||||||||||||
| var uri = "https://example.com/"; | ||||||||||||||
| Assert.True(_baseUri.IsBaseOfPage(uri)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| [Fact] | ||||||||||||||
| public void IsBaseOfPage_IgnoresDotInQuery_WhenBaseUriMatches() | ||||||||||||||
| { | ||||||||||||||
| var uri = "https://example.com/page?foo=1.2.3"; | ||||||||||||||
| Assert.True(_baseUri.IsBaseOfPage(uri)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| [Fact] | ||||||||||||||
| public void IsBaseOfPage_ReturnsFalse_WhenSchemeDiffersFromBase() | ||||||||||||||
| { | ||||||||||||||
| var uri = "ftp://example.com/page"; | ||||||||||||||
| Assert.False(_baseUri.IsBaseOfPage(uri)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| [Fact] | ||||||||||||||
| public void IsBaseOfPage_DoesNotTreatDotInQueryAsExtension() | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Regression Prevention — Missing issue reference on primary regression test — // Regression test for https://github.com/dotnet/maui/issues/25689
// A URL with a dot in the query parameter (e.g. ?weight=62.5) must not be
// treated as a file-extension path and must be allowed to fall back to the host page.
[Fact]
public void IsBaseOfPage_DoesNotTreatDotInQueryAsExtension()Without this comment, the test is indistinguishable from the duplicate facts above and its specific regression value is invisible. |
||||||||||||||
| { | ||||||||||||||
| var baseUri = new Uri("https://example.com"); | ||||||||||||||
| var urlWithDotInQuery = "https://example.com/customer?weight=62.5"; | ||||||||||||||
| Assert.True(baseUri.IsBaseOfPage(urlWithDotInQuery)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| [Fact] | ||||||||||||||
| public void IsBaseOfPage_ReturnsFalse_WhenPathHasDotExtension() | ||||||||||||||
| { | ||||||||||||||
| var baseUri = new Uri("https://example.com"); | ||||||||||||||
| var urlWithExtension = "https://example.com/customer.json"; | ||||||||||||||
| Assert.False(baseUri.IsBaseOfPage(urlWithExtension)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| [Fact] | ||||||||||||||
| public void IsBaseOfPage_TreatsFragmentWithDotAsNoExtension() | ||||||||||||||
| { | ||||||||||||||
| var baseUri = new Uri("https://example.com"); | ||||||||||||||
| var urlWithDotInFragment = "https://example.com/customer#section.1"; | ||||||||||||||
| Assert.True(baseUri.IsBaseOfPage(urlWithDotInFragment)); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.