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) <noreply@anthropic.com>claude/bold-hawking
parent
f224d1788c
commit
64669888c2
|
|
@ -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<ExtractedSocialLinks>[]): 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue