feat(blocks): add typed personalization resolution
This commit is contained in:
1 parent
2428df6e78
commit
157eec7a78
9 files changed
+128
-12
No files matched your search
@@ -92,8 +92,14 @@ export function safeUrl(
|
||||
if ((value === undefined || value === "") && options.optional) return { ok: true, value: "" };
|
||||
if (typeof value !== "string" || value.length > 4_096)
|
||||
return fail("schema.url", "Expected a bounded URL.", path);
|
||||
const token = /^\{\{\s*[A-Za-z][A-Za-z0-9_.-]*(?:\|[^{}]*)?\s*\}\}$/;
|
||||
if (token.test(value)) return { ok: true, value };
|
||||
try {
|
||||
const parsed = new URL(value);
|
||||
const templated = value.replace(
|
||||
/\{\{\s*[A-Za-z][A-Za-z0-9_.-]*(?:\|[^{}]*)?\s*\}\}/g,
|
||||
"variable",
|
||||
);
|
||||
const parsed = new URL(templated);
|
||||
return schemes.has(parsed.protocol.replace(/:$/, ""))
|
||||
? { ok: true, value: parsed.href }
|
||||
: fail("schema.url.scheme", `URL scheme ${parsed.protocol} is not allowed.`, path);
|
||||
|
||||
Reference in new issue
Block a user