17 lines
455 B
TypeScript
17 lines
455 B
TypeScript
export function safeNotificationActionUrl(value: string | null | undefined): string | null {
|
|
const candidate = value?.trim();
|
|
if (
|
|
!candidate
|
|
|| !candidate.startsWith("/")
|
|
|| candidate.startsWith("//")
|
|
|| candidate.includes("\\")
|
|
|| [...candidate].some((character) => {
|
|
const codePoint = character.codePointAt(0) ?? 0;
|
|
return codePoint < 32 || codePoint === 127;
|
|
})
|
|
) {
|
|
return null;
|
|
}
|
|
return candidate;
|
|
}
|