Fix Astro.params does not contain path parameter from URL with non-English characters (#6859)
This commit is contained in:
parent
1ed52c5849
commit
4c7ba4da08
4 changed files with 32 additions and 1 deletions
5
.changeset/few-cats-beam.md
Normal file
5
.changeset/few-cats-beam.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix Astro.params does not contain path parameter from URL with non-English characters.
|
|
@ -32,7 +32,9 @@ export async function getParamsAndProps(
|
|||
let pageProps: Props;
|
||||
if (route && !route.pathname) {
|
||||
if (route.params.length) {
|
||||
const paramsMatch = route.pattern.exec(pathname);
|
||||
// The RegExp pattern expects a decoded string, but the pathname is encoded
|
||||
// when the URL contains non-English characters.
|
||||
const paramsMatch = route.pattern.exec(decodeURIComponent(pathname));
|
||||
if (paramsMatch) {
|
||||
params = getParams(route.params)(paramsMatch);
|
||||
|
||||
|
|
12
packages/astro/test/fixtures/ssr-params/src/pages/東西/[category].astro
vendored
Normal file
12
packages/astro/test/fixtures/ssr-params/src/pages/東西/[category].astro
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
const { category } = Astro.params
|
||||
---
|
||||
<html>
|
||||
<head>
|
||||
<title>Testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Testing</h1>
|
||||
<h2 class="category">{ category }</h2>
|
||||
</body>
|
||||
</html>
|
|
@ -26,4 +26,16 @@ describe('Astro.params in SSR', () => {
|
|||
const $ = cheerio.load(html);
|
||||
expect($('.category').text()).to.equal('food');
|
||||
});
|
||||
|
||||
describe('Non-english characters in the URL', () => {
|
||||
it('Params are passed to component', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/users/houston/東西/food');
|
||||
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('food');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue