summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2025-02-26 16:29:32 +0000
committerGravatar GitHub <noreply@github.com> 2025-02-26 16:29:32 +0000
commit5f72a58935d9bdd5237bdf86d2e94bcdc544c7b3 (patch)
tree692fff3736b869243427aeb0ba10119e4c6dfe6c
parent2154adaeada26aea7b03f1f10d212a4624cfc3b9 (diff)
downloadastro-5f72a58935d9bdd5237bdf86d2e94bcdc544c7b3.tar.gz
astro-5f72a58935d9bdd5237bdf86d2e94bcdc544c7b3.tar.zst
astro-5f72a58935d9bdd5237bdf86d2e94bcdc544c7b3.zip
fix(core): double encoding during match of routes (#13303)
Co-authored-by: florian-lefebvre <69633530+florian-lefebvre@users.noreply.github.com>
-rw-r--r--.changeset/stale-oranges-call.md5
-rw-r--r--packages/astro/src/core/app/index.ts2
-rw-r--r--packages/astro/src/core/build/generate.ts2
-rw-r--r--packages/astro/src/core/routing/match.ts7
-rw-r--r--packages/astro/test/params.test.js1
5 files changed, 11 insertions, 6 deletions
diff --git a/.changeset/stale-oranges-call.md b/.changeset/stale-oranges-call.md
new file mode 100644
index 000000000..dd21fc492
--- /dev/null
+++ b/.changeset/stale-oranges-call.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes an issue where the dev server was applying second decoding of the URL of the incoming request, causing issues for certain URLs.
diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts
index 543d82d0f..f76408078 100644
--- a/packages/astro/src/core/app/index.ts
+++ b/packages/astro/src/core/app/index.ts
@@ -177,7 +177,7 @@ export class App {
if (!pathname) {
pathname = prependForwardSlash(this.removeBase(url.pathname));
}
- let routeData = matchRoute(pathname, this.#manifestData);
+ let routeData = matchRoute(decodeURI(pathname), this.#manifestData);
// missing routes fall-through, pre rendered are handled by static layer
if (!routeData || routeData.prerender) return undefined;
diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts
index d8df4bccf..0d5c049fc 100644
--- a/packages/astro/src/core/build/generate.ts
+++ b/packages/astro/src/core/build/generate.ts
@@ -360,7 +360,7 @@ async function getPathsForRoute(
// NOTE: The same URL may match multiple routes in the manifest.
// Routing priority needs to be verified here for any duplicate
// paths to ensure routing priority rules are enforced in the final build.
- const matchedRoute = matchRoute(staticPath, options.routesList);
+ const matchedRoute = matchRoute(decodeURI(staticPath), options.routesList);
return matchedRoute === route;
});
diff --git a/packages/astro/src/core/routing/match.ts b/packages/astro/src/core/routing/match.ts
index 45ad8f595..caa3ae743 100644
--- a/packages/astro/src/core/routing/match.ts
+++ b/packages/astro/src/core/routing/match.ts
@@ -5,18 +5,17 @@ import { SERVER_ISLAND_BASE_PREFIX, SERVER_ISLAND_COMPONENT } from '../server-is
/** Find matching route from pathname */
export function matchRoute(pathname: string, manifest: RoutesList): RouteData | undefined {
- const decodedPathname = decodeURI(pathname);
return manifest.routes.find((route) => {
return (
- route.pattern.test(decodedPathname) ||
- route.fallbackRoutes.some((fallbackRoute) => fallbackRoute.pattern.test(decodedPathname))
+ route.pattern.test(pathname) ||
+ route.fallbackRoutes.some((fallbackRoute) => fallbackRoute.pattern.test(pathname))
);
});
}
/** Finds all matching routes from pathname */
export function matchAllRoutes(pathname: string, manifest: RoutesList): RouteData[] {
- return manifest.routes.filter((route) => route.pattern.test(decodeURI(pathname)));
+ return manifest.routes.filter((route) => route.pattern.test(pathname));
}
const ROUTE404_RE = /^\/404\/?$/;
diff --git a/packages/astro/test/params.test.js b/packages/astro/test/params.test.js
index 60890637d..7917e32f1 100644
--- a/packages/astro/test/params.test.js
+++ b/packages/astro/test/params.test.js
@@ -113,6 +113,7 @@ describe('Astro.params in dev mode', () => {
const $ = cheerio.load(html);
assert.equal($('.category').text(), '你好');
});
+
});
describe('Astro.params in static mode', () => {