Harden campaign import handling
This commit is contained in:
@@ -21,6 +21,10 @@ export function asArray(value: unknown): unknown[] {
|
||||
return Array.isArray(value) ? value : [];
|
||||
}
|
||||
|
||||
export function isSafeObjectPathSegment(segment: string): boolean {
|
||||
return segment !== "__proto__" && segment !== "prototype" && segment !== "constructor";
|
||||
}
|
||||
|
||||
export function getCampaignJson(version: CampaignVersionDetail | null): Record<string, unknown> {
|
||||
return version?.raw_json ?? version?.campaign_json ?? {};
|
||||
}
|
||||
@@ -179,10 +183,11 @@ export function getString(record: Record<string, unknown>, key: string, fallback
|
||||
}
|
||||
|
||||
export function getNestedString(record: Record<string, unknown>, path: string[], fallback = "—"): string {
|
||||
if (!path.every(isSafeObjectPathSegment)) return fallback;
|
||||
let current: unknown = record;
|
||||
for (const part of path) {
|
||||
if (!isRecord(current)) return fallback;
|
||||
current = current[part];
|
||||
current = Object.getOwnPropertyDescriptor(current, part)?.value;
|
||||
}
|
||||
if (typeof current === "string" && current.trim()) return current;
|
||||
if (typeof current === "number" || typeof current === "boolean") return String(current);
|
||||
|
||||
Reference in New Issue
Block a user