Skip to content
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

[Blazor] Correctly encode non-ASCII characters in redirect URL #53623

Merged
merged 1 commit into from
Jan 26, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ internal sealed class HttpNavigationManager : NavigationManager, IHostEnvironmen

protected override void NavigateToCore(string uri, NavigationOptions options)
{
var absoluteUriString = ToAbsoluteUri(uri).ToString();
var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
Copy link
Member Author

Choose a reason for hiding this comment

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

Accessing the Uri.AbsoluteUri property will throw if the Uri instance does not represent an absolute URI, but this case is safe because ToAbsoluteUri() always returns an absolute URI.

throw new NavigationException(absoluteUriString);
}
}
Original file line number Diff line number Diff line change
@@ -516,7 +516,7 @@ class FakeNavigationManager : NavigationManager, IHostEnvironmentNavigationManag
protected override void NavigateToCore(string uri, NavigationOptions options)
{
// Equivalent to what RemoteNavigationManager would do
var absoluteUriString = ToAbsoluteUri(uri).ToString();
var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
throw new NavigationException(absoluteUriString);
}
}
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ protected override void NavigateToCore(string uri, NavigationOptions options)

if (_jsRuntime == null)
{
var absoluteUriString = ToAbsoluteUri(uri).ToString();
var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
throw new NavigationException(absoluteUriString);
}

@@ -128,7 +128,7 @@ public override void Refresh(bool forceReload = false)
{
if (_jsRuntime == null)
{
var absoluteUriString = ToAbsoluteUri(Uri).ToString();
var absoluteUriString = ToAbsoluteUri(Uri).AbsoluteUri;
throw new NavigationException(absoluteUriString);
}

Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public void RedirectStreamingGetToInternal()
AssertElementRemoved(_originalH1Element);
Browser.Equal("Scroll to hash", () => Browser.Exists(By.TagName("h1")).Text);
Browser.True(() => Browser.GetScrollY() > 500);
Assert.EndsWith("/subdir/nav/scroll-to-hash#some-content", Browser.Url);
Assert.EndsWith("/subdir/nav/scroll-to-hash?foo=%F0%9F%99%82#some-content", Browser.Url);

// See that 'back' takes you to the place from before the redirection
Browser.Navigate().Back();
@@ -61,7 +61,7 @@ public void RedirectStreamingPostToInternal()
AssertElementRemoved(_originalH1Element);
Browser.Equal("Scroll to hash", () => Browser.Exists(By.TagName("h1")).Text);
Browser.True(() => Browser.GetScrollY() > 500);
Assert.EndsWith("/subdir/nav/scroll-to-hash#some-content", Browser.Url);
Assert.EndsWith("/subdir/nav/scroll-to-hash?foo=%F0%9F%99%82#some-content", Browser.Url);

// See that 'back' takes you to the place from before the redirection
Browser.Navigate().Back();
@@ -87,7 +87,7 @@ public void RedirectEnhancedGetToInternal()

Browser.Exists(By.LinkText("Enhanced GET with internal redirection")).Click();
Browser.Equal("Scroll to hash", () => _originalH1Element.Text);
Assert.EndsWith("/subdir/nav/scroll-to-hash", Browser.Url);
Assert.EndsWith("/subdir/nav/scroll-to-hash?foo=%F0%9F%99%82", Browser.Url);

// See that 'back' takes you to the place from before the redirection
Browser.Navigate().Back();
@@ -108,7 +108,7 @@ public void RedirectEnhancedPostToInternal()
// See above for why enhanced nav doesn't support preserving the hash
Browser.Exists(By.CssSelector("#form-enhanced-internal button")).Click();
Browser.Equal("Scroll to hash", () => _originalH1Element.Text);
Assert.EndsWith("/subdir/nav/scroll-to-hash", Browser.Url);
Assert.EndsWith("/subdir/nav/scroll-to-hash?foo=%F0%9F%99%82", Browser.Url);

// See that 'back' takes you to the place from before the redirection
Browser.Navigate().Back();
@@ -129,7 +129,7 @@ public void RedirectStreamingEnhancedGetToInternal()
// See above for why enhanced nav doesn't support preserving the hash
Browser.Exists(By.LinkText("Streaming enhanced GET with internal redirection")).Click();
Browser.Equal("Scroll to hash", () => _originalH1Element.Text);
Assert.EndsWith("/subdir/nav/scroll-to-hash", Browser.Url);
Assert.EndsWith("/subdir/nav/scroll-to-hash?foo=%F0%9F%99%82", Browser.Url);

// See that 'back' takes you to the place from before the redirection
Browser.Navigate().Back();
@@ -150,7 +150,7 @@ public void RedirectStreamingEnhancedPostToInternal()
// See above for why enhanced nav doesn't support preserving the hash
Browser.Exists(By.CssSelector("#form-streaming-enhanced-internal button")).Click();
Browser.Equal("Scroll to hash", () => _originalH1Element.Text);
Assert.EndsWith("/subdir/nav/scroll-to-hash", Browser.Url);
Assert.EndsWith("/subdir/nav/scroll-to-hash?foo=%F0%9F%99%82", Browser.Url);

// See that 'back' takes you to the place from before the redirection
Browser.Navigate().Back();
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@
protected override async Task OnInitializedAsync()
{
await Task.Delay(500);
Nav.NavigateTo(External ? "https://microsoft.com" : "nav/scroll-to-hash#some-content");
Nav.NavigateTo(External ? "https://microsoft.com?foo=🙂" : "nav/scroll-to-hash?foo=🙂#some-content");
}
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@
private async Task DoRedirectionAsync()
{
await Task.Delay(500);
Nav.NavigateTo(External ? "https://microsoft.com" : "nav/scroll-to-hash#some-content");
Nav.NavigateTo(External ? "https://microsoft.com?foo=🙂" : "nav/scroll-to-hash?foo=🙂#some-content");
}
}
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@
protected override async Task OnInitializedAsync()
{
await Task.Delay(500);
Nav.NavigateTo(External ? "https://microsoft.com" : "nav/scroll-to-hash#some-content");
Nav.NavigateTo(External ? "https://microsoft.com?foo=🙂" : "nav/scroll-to-hash?foo=🙂#some-content");
}
}
Original file line number Diff line number Diff line change
@@ -13,6 +13,6 @@
private async Task DoRedirectionAsync()
{
await Task.Delay(500);
Nav.NavigateTo(External ? "https://microsoft.com" : "nav/scroll-to-hash#some-content");
Nav.NavigateTo(External ? "https://microsoft.com?foo=🙂" : "nav/scroll-to-hash?foo=🙂#some-content");
}
}