Reject empty asset paths

This commit is contained in:
scamiv
2026-03-23 00:58:05 +01:00
parent 110dcc2e54
commit b9732ce853
2 changed files with 14 additions and 1 deletions
+7 -1
View File
@@ -30,12 +30,18 @@ export function encodeAssetPath(path: string): string {
}
export function normalizeAssetPath(path: string): string {
return path
const normalizedPath = path
.replace(/^\/+/, "")
.split("/")
.filter((segment) => segment.length > 0)
.map((segment) => assertSafeAssetSegment(segment))
.join("/");
if (normalizedPath.length === 0) {
throw new Error("Asset path must not be empty");
}
return normalizedPath;
}
export function buildAssetUrl(
+7
View File
@@ -36,4 +36,11 @@ describe("AssetUrls", () => {
"Invalid asset path segment: %2e%2e",
);
});
test("rejects empty asset paths", () => {
expect(() => buildAssetUrl("", {})).toThrow("Asset path must not be empty");
expect(() => buildAssetUrl("///", {})).toThrow(
"Asset path must not be empty",
);
});
});