From 4c7ba4da084d7508df91cbac03c2b099a8301e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Alves?= <71379045+andremralves@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:44:48 -0300 Subject: [PATCH] Fix Astro.params does not contain path parameter from URL with non-English characters (#6859) --- .changeset/few-cats-beam.md | 5 +++++ packages/astro/src/core/render/core.ts | 4 +++- .../ssr-params/src/pages/東西/[category].astro | 12 ++++++++++++ packages/astro/test/ssr-params.test.js | 12 ++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .changeset/few-cats-beam.md create mode 100644 packages/astro/test/fixtures/ssr-params/src/pages/東西/[category].astro 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 +--- + +
+