0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

Prevent double uri decoding (#9532)

This commit is contained in:
Bjorn Lu 2023-12-28 00:34:28 +07:00 committed by GitHub
parent d252fc61b0
commit 7224809b73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Prevents unnecessary URI decoding when rendering a route

View file

@ -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;

View file

@ -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

View file

@ -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('%');
});
});