Skip to content

Commit 7224809

Browse files
authoredDec 27, 2023
Prevent double uri decoding (#9532)
1 parent d252fc6 commit 7224809

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed
 

‎.changeset/old-goats-occur.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Prevents unnecessary URI decoding when rendering a route

‎packages/astro/src/core/routing/params.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export function getParams(array: string[]) {
1212
const params: Params = {};
1313
array.forEach((key, i) => {
1414
if (key.startsWith('...')) {
15-
params[key.slice(3)] = match[i + 1] ? decodeURIComponent(match[i + 1]) : undefined;
15+
params[key.slice(3)] = match[i + 1] ? match[i + 1] : undefined;
1616
} else {
17-
params[key] = decodeURIComponent(match[i + 1]);
17+
params[key] = match[i + 1];
1818
}
1919
});
2020
return params;

‎packages/astro/src/vite-plugin-astro-server/request.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function handleRequest({
3737
if (config.trailingSlash === 'never' && !incomingRequest.url) {
3838
pathname = '';
3939
} else {
40-
pathname = decodeURI(url.pathname);
40+
pathname = url.pathname;
4141
}
4242

4343
// Add config.base back to url before passing it to SSR

‎packages/astro/test/ssr-params.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,14 @@ describe('Astro.params in SSR', () => {
3838
expect($('.category').text()).to.equal('food');
3939
});
4040
});
41+
42+
it('No double URL decoding', async () => {
43+
const app = await fixture.loadTestAdapterApp();
44+
const request = new Request('http://example.com/users/houston/%25');
45+
const response = await app.render(request);
46+
expect(response.status).to.equal(200);
47+
const html = await response.text();
48+
const $ = cheerio.load(html);
49+
expect($('.category').text()).to.equal('%');
50+
});
4151
});

0 commit comments

Comments
 (0)
Please sign in to comment.