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:
parent
d252fc61b0
commit
7224809b73
4 changed files with 18 additions and 3 deletions
5
.changeset/old-goats-occur.md
Normal file
5
.changeset/old-goats-occur.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Prevents unnecessary URI decoding when rendering a route
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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('%');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue