From 0d769ffb6445383019dd89dac73288e882e3dcac Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 12:17:58 +0100 Subject: [PATCH] Pages corrections --- app/pages/page.tsx | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/app/pages/page.tsx b/app/pages/page.tsx index e0369c1..603d378 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -183,14 +183,46 @@ export default function CarnetPage() { try { console.log(`[parseVCardContent] Parsing VCF content, length: ${content.length}`); - // Split the content into individual vCards - // Handle both formats: BEGIN:VCARD\n... and BEGIN:VCARD\r\n... - const vcards = content.split(/BEGIN:VCARD/i).filter(section => section.trim()); - console.log(`[parseVCardContent] Found ${vcards.length} vCard sections`); + // Normalize line endings and split vCards + // Replace \r\n with \n, then split by BEGIN:VCARD + const normalizedContent = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); - const parsed = vcards.map((section, index) => { + // Split the content into individual vCards + // Handle formats like: BEGIN:VCARD\n... or BEGIN:VCARDVERSION:3.0... + const vcardSections = normalizedContent.split(/BEGIN:VCARD/i).filter(section => section.trim()); + console.log(`[parseVCardContent] Found ${vcardSections.length} vCard sections`); + + const parsed = vcardSections.map((section, index) => { try { - const vcardContent = 'BEGIN:VCARD' + section; + // Reconstruct vCard content with proper formatting + let vcardContent = 'BEGIN:VCARD\n'; + + // Clean up the section and ensure proper line breaks + let cleanedSection = section.trim(); + + // Fix format where BEGIN:VCARD is directly followed by VERSION (no newline) + cleanedSection = cleanedSection.replace(/^VERSION:/, 'VERSION:'); + + // Ensure each field is on its own line + cleanedSection = cleanedSection + .replace(/([^\n])(VERSION:)/g, '$1\n$2') + .replace(/([^\n])(UID:)/g, '$1\n$2') + .replace(/([^\n])(FN:)/g, '$1\n$2') + .replace(/([^\n])(EMAIL)/g, '$1\n$2') + .replace(/([^\n])(TEL)/g, '$1\n$2') + .replace(/([^\n])(ORG:)/g, '$1\n$2') + .replace(/([^\n])(NOTE:)/g, '$1\n$2') + .replace(/([^\n])(END:VCARD)/g, '$1\n$2'); + + vcardContent += cleanedSection; + + // Ensure it ends with END:VCARD + if (!vcardContent.trim().endsWith('END:VCARD')) { + vcardContent += '\nEND:VCARD'; + } + + console.log(`[parseVCardContent] Processing vCard ${index + 1}, content preview:`, vcardContent.substring(0, 300)); + const vcard = parseVCard(vcardContent); // Extract contact properties with proper type handling