mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
fix(core): double encoding during match of routes (#13303)
Co-authored-by: florian-lefebvre <69633530+florian-lefebvre@users.noreply.github.com>
This commit is contained in:
parent
2154adaead
commit
5f72a58935
5 changed files with 11 additions and 6 deletions
5
.changeset/stale-oranges-call.md
Normal file
5
.changeset/stale-oranges-call.md
Normal file
|
@ -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.
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
@ -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\/?$/;
|
||||
|
|
|
@ -113,6 +113,7 @@ describe('Astro.params in dev mode', () => {
|
|||
const $ = cheerio.load(html);
|
||||
assert.equal($('.category').text(), '你好');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Astro.params in static mode', () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue