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); } }