Skip to content

Commit

Permalink
sperated sanitizing of generated paths and ssr dynamic paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias-Chairi committed May 13, 2024
1 parent d65c4c9 commit 80457ad
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/astro/src/core/routing/manifest/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@ import type { AstroConfig, RoutePart } from '../../../@types/astro.js';

import { compile } from 'path-to-regexp';

function sanitizePath(path: string) {
return path.normalize()
.replace(/\?/g, "%3F")
.replace(/#/g, "%23")
.replace(/%5B/g, "[")
.replace(/%5D/g, "]")
.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

function sanitizeParams(params: Record<string, string | number | undefined>): Record<string, string | number | undefined> {
return Object.entries(params).reduce((acc, [key, value]) => {
if (typeof value === "string") {
acc[key] = sanitizePath(value);
acc[key] = value
.normalize()
.replace(/#/g, "%23")
.replace(/\?/g, "%3F")
} else {
acc[key] = value;
}
Expand All @@ -37,7 +31,13 @@ export function getRouteGenerator(
} else if (part.dynamic) {
return `:${part.content}`;
} else {
return sanitizePath(part.content)
return part.content
.normalize()
.replace(/\?/g, "%3F")
.replace(/#/g, "%23")
.replace(/%5B/g, "[")
.replace(/%5D/g, "]")
.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
})
.join('')
Expand Down

0 comments on commit 80457ad

Please sign in to comment.