Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/tests/e2e/utils/local-path.ts
T

29 lines
812 B
TypeScript

const E2E_LOCAL_PATH_ORIGIN = "https://hivegrid-e2e.invalid";
export function requireCanonicalE2eLocalPath(value: string, inputName: string): string {
let resolved: URL;
try {
resolved = new URL(value, E2E_LOCAL_PATH_ORIGIN);
} catch {
throw invalidLocalPath(inputName);
}
if (
!value.startsWith("/") ||
value.startsWith("//") ||
value.includes("\\") ||
value.includes("%") ||
/[\u0000-\u001f\u007f]/u.test(value) ||
resolved.origin !== E2E_LOCAL_PATH_ORIGIN ||
resolved.pathname !== value ||
resolved.search ||
resolved.hash
) {
throw invalidLocalPath(inputName);
}
return value;
}
function invalidLocalPath(inputName: string): Error {
return new Error(`${inputName} must be a canonical app-local absolute path without query or fragment.`);
}