Skip to content

Commit f75a209

Browse files
committed
fix(@angular/ssr): prevent redirect loop with encoded query parameters
Previously, encoded query parameters caused a mismatch between the requested URL and the reconstructed URL, leading to a redirect loop. This change ensures both URLs are decoded before comparison. Closes #31881
1 parent 2671945 commit f75a209

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/angular/ssr/src/utils/ng.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ export async function renderAngular(
111111
hasNavigationError = false;
112112
const { pathname, search, hash } = envInjector.get(PlatformLocation);
113113
const finalUrl = [stripTrailingSlash(pathname), search, hash].join('');
114+
const finalUrlHref = decodeURIComponent(new URL(finalUrl, urlToRender.origin).href);
115+
const urlToRenderHref = decodeURIComponent(urlToRender.href);
114116

115-
if (urlToRender.href !== new URL(finalUrl, urlToRender.origin).href) {
117+
if (urlToRenderHref !== finalUrlHref) {
116118
redirectTo = finalUrl;
117119
}
118120
}

packages/angular/ssr/test/app-engine_spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,12 @@ describe('AngularAppEngine', () => {
269269
const response = await appEngine.handle(request);
270270
expect(await response?.text()).toContain('Home works');
271271
});
272+
273+
it('should not decode query parameters', async () => {
274+
const request = new Request('https://example.com/home?email=xyz%40xyz.com');
275+
const response = await appEngine.handle(request);
276+
expect(response?.status).toBe(200);
277+
expect(await response?.text()).toContain('Home works');
278+
});
272279
});
273280
});

0 commit comments

Comments
 (0)