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

Fix an issue where certain characters break redirects in SSR #10411

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/yellow-clocks-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes an issue where certain characters break redirects in SSR.
2 changes: 1 addition & 1 deletion packages/astro/src/core/redirects/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function renderRedirect(renderContext: RenderContext) {
const { redirect, redirectRoute } = routeData;
const status =
redirectRoute && typeof redirect === 'object' ? redirect.status : method === 'GET' ? 301 : 308;
const headers = { location: redirectRouteGenerate(renderContext) };
const headers = { location: encodeURI(redirectRouteGenerate(renderContext)) };
return new Response(null, { status, headers });
}

Expand Down
10 changes: 10 additions & 0 deletions packages/astro/test/redirects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ describe('Astro.redirect', () => {
const response = await app.render(request);
assert.equal(response.headers.get('Location'), '/not-verbatim/target3/x/y/z');
});

it('Forwards params to the target path - special characters', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/source/Las Vegas’');
const response = await app.render(request);
assert.equal(
response.headers.get('Location'),
'/not-verbatim/target1/Las%20Vegas%E2%80%99'
);
});
});
});

Expand Down
Loading