From 64669888c25432dd6ceae377efd652ebf5737bf2 Mon Sep 17 00:00:00 2001 From: Haewon Kam Date: Sat, 4 Apr 2026 01:17:49 +0900 Subject: [PATCH] fix: type-safe string handling in extractSocialLinks/mergeSocialLinks API results may contain null, numbers, or objects instead of strings. Now coerces all values to strings before processing. Co-Authored-By: Claude Opus 4.6 (1M context) --- supabase/functions/_shared/extractSocialLinks.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/supabase/functions/_shared/extractSocialLinks.ts b/supabase/functions/_shared/extractSocialLinks.ts index ea45784..008fe18 100644 --- a/supabase/functions/_shared/extractSocialLinks.ts +++ b/supabase/functions/_shared/extractSocialLinks.ts @@ -79,8 +79,10 @@ export function extractSocialLinks(urls: string[]): ExtractedSocialLinks { seen[key] = new Set(); } - for (const url of urls) { - if (!url || typeof url !== 'string') continue; + for (const rawUrl of urls) { + // Ensure we only process strings + const url = typeof rawUrl === 'string' ? rawUrl : String(rawUrl || ''); + if (!url || url.length < 5) continue; for (const { platform, regex, extract } of PATTERNS) { const match = url.match(regex); @@ -121,8 +123,9 @@ export function mergeSocialLinks(...sources: Partial[]): E for (const key of Object.keys(merged) as (keyof ExtractedSocialLinks)[]) { const vals = source[key]; if (Array.isArray(vals)) { - for (const v of vals) { - if (v && !merged[key].some(existing => existing.toLowerCase() === v.toLowerCase())) { + for (const rawV of vals) { + const v = typeof rawV === 'string' ? rawV.trim() : ''; + if (v && v.length >= 2 && !merged[key].some(existing => existing.toLowerCase() === v.toLowerCase())) { merged[key].push(v); } }