Skip to content

Commit 335c8de

Browse files
Correctly encode non-ASCII characters in redirect URL (#53623)
1 parent 6048826 commit 335c8de

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal sealed class HttpNavigationManager : NavigationManager, IHostEnvironmen
1111

1212
protected override void NavigateToCore(string uri, NavigationOptions options)
1313
{
14-
var absoluteUriString = ToAbsoluteUri(uri).ToString();
14+
var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
1515
throw new NavigationException(absoluteUriString);
1616
}
1717
}

src/Components/Endpoints/test/RazorComponentResultTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class FakeNavigationManager : NavigationManager, IHostEnvironmentNavigationManag
516516
protected override void NavigateToCore(string uri, NavigationOptions options)
517517
{
518518
// Equivalent to what RemoteNavigationManager would do
519-
var absoluteUriString = ToAbsoluteUri(uri).ToString();
519+
var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
520520
throw new NavigationException(absoluteUriString);
521521
}
522522
}

src/Components/Server/src/Circuits/RemoteNavigationManager.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
8787

8888
if (_jsRuntime == null)
8989
{
90-
var absoluteUriString = ToAbsoluteUri(uri).ToString();
90+
var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
9191
throw new NavigationException(absoluteUriString);
9292
}
9393

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

src/Components/test/E2ETest/ServerRenderingTests/RedirectionTest.cs

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

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

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

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

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

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

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

155155
// See that 'back' takes you to the place from before the redirection
156156
Browser.Navigate().Back();

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Redirections/RedirectGet.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
protected override async Task OnInitializedAsync()
1111
{
1212
await Task.Delay(500);
13-
Nav.NavigateTo(External ? "https://microsoft.com" : "nav/scroll-to-hash#some-content");
13+
Nav.NavigateTo(External ? "https://microsoft.com?foo=🙂" : "nav/scroll-to-hash?foo=🙂#some-content");
1414
}
1515
}

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Redirections/RedirectPost.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
private async Task DoRedirectionAsync()
1313
{
1414
await Task.Delay(500);
15-
Nav.NavigateTo(External ? "https://microsoft.com" : "nav/scroll-to-hash#some-content");
15+
Nav.NavigateTo(External ? "https://microsoft.com?foo=🙂" : "nav/scroll-to-hash?foo=🙂#some-content");
1616
}
1717
}

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Redirections/RedirectStreamingGet.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
protected override async Task OnInitializedAsync()
1212
{
1313
await Task.Delay(500);
14-
Nav.NavigateTo(External ? "https://microsoft.com" : "nav/scroll-to-hash#some-content");
14+
Nav.NavigateTo(External ? "https://microsoft.com?foo=🙂" : "nav/scroll-to-hash?foo=🙂#some-content");
1515
}
1616
}

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Redirections/RedirectStreamingPost.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
private async Task DoRedirectionAsync()
1414
{
1515
await Task.Delay(500);
16-
Nav.NavigateTo(External ? "https://microsoft.com" : "nav/scroll-to-hash#some-content");
16+
Nav.NavigateTo(External ? "https://microsoft.com?foo=🙂" : "nav/scroll-to-hash?foo=🙂#some-content");
1717
}
1818
}

0 commit comments

Comments
 (0)