Skip to content

Commit

Permalink
Prevent double uri decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Dec 27, 2023
1 parent cf993bc commit 1692f1e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-goats-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prevents unnecessary URI decoding when rendering a route
4 changes: 2 additions & 2 deletions packages/astro/src/core/routing/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export function getParams(array: string[]) {
const params: Params = {};
array.forEach((key, i) => {
if (key.startsWith('...')) {
params[key.slice(3)] = match[i + 1] ? decodeURIComponent(match[i + 1]) : undefined;
params[key.slice(3)] = match[i + 1] ? match[i + 1] : undefined;
} else {
params[key] = decodeURIComponent(match[i + 1]);
params[key] = match[i + 1];
}
});
return params;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-server/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function handleRequest({
if (config.trailingSlash === 'never' && !incomingRequest.url) {
pathname = '';
} else {
pathname = decodeURI(url.pathname);
pathname = url.pathname;
}

// Add config.base back to url before passing it to SSR
Expand Down
10 changes: 10 additions & 0 deletions packages/astro/test/ssr-params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ describe('Astro.params in SSR', () => {
expect($('.category').text()).to.equal('food');
});
});

it('No double URL decoding', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/users/houston/%25');
const response = await app.render(request);
expect(response.status).to.equal(200);
const html = await response.text();
const $ = cheerio.load(html);
expect($('.category').text()).to.equal('%');
});
});

0 comments on commit 1692f1e

Please sign in to comment.