summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar André Alves <71379045+andremralves@users.noreply.github.com> 2023-04-17 11:44:48 -0300
committerGravatar GitHub <noreply@github.com> 2023-04-17 16:44:48 +0200
commit4c7ba4da084d7508df91cbac03c2b099a8301e2b (patch)
tree3025b6a4834b632c1ce3470d134ee03ac922fc52
parent1ed52c5849a9a268d9e8f07f14e5c67e65ea289d (diff)
downloadastro-4c7ba4da084d7508df91cbac03c2b099a8301e2b.tar.gz
astro-4c7ba4da084d7508df91cbac03c2b099a8301e2b.tar.zst
astro-4c7ba4da084d7508df91cbac03c2b099a8301e2b.zip
Fix Astro.params does not contain path parameter from URL with non-English characters (#6859)
-rw-r--r--.changeset/few-cats-beam.md5
-rw-r--r--packages/astro/src/core/render/core.ts4
-rw-r--r--packages/astro/test/fixtures/ssr-params/src/pages/東西/[category].astro12
-rw-r--r--packages/astro/test/ssr-params.test.js12
4 files changed, 32 insertions, 1 deletions
diff --git a/.changeset/few-cats-beam.md b/.changeset/few-cats-beam.md
new file mode 100644
index 000000000..7585992ce
--- /dev/null
+++ b/.changeset/few-cats-beam.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix Astro.params does not contain path parameter from URL with non-English characters.
diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts
index d072c85b4..8687e9006 100644
--- a/packages/astro/src/core/render/core.ts
+++ b/packages/astro/src/core/render/core.ts
@@ -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);
diff --git a/packages/astro/test/fixtures/ssr-params/src/pages/東西/[category].astro b/packages/astro/test/fixtures/ssr-params/src/pages/東西/[category].astro
new file mode 100644
index 000000000..bdaa1f965
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-params/src/pages/東西/[category].astro
@@ -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>
diff --git a/packages/astro/test/ssr-params.test.js b/packages/astro/test/ssr-params.test.js
index 37155425e..343e47cf8 100644
--- a/packages/astro/test/ssr-params.test.js
+++ b/packages/astro/test/ssr-params.test.js
@@ -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');
+ });
+ });
});