mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 17:26:42 +00:00
Reject empty asset paths
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user