fix(vcf): handle vCard properties with parameters

CO
7h ago
+31-5

Summary

Fixes an issue in the VCF (vCard) contact parser where FN (Full Name), N (Name), and ORG (Organization) fields are silently dropped during conversion to CSV whenever they contain property parameters (e.g., CHARSET=UTF-8, LANGUAGE=en-US).


Background & Problem

When contacts are exported from modern address books (such as Google Contacts, Android Contacts, Apple Address Book, or Microsoft Outlook)—especially contacts containing international characters or diacritics—properties are standardly encoded with parameters:

BEGIN:VCARD
VERSION:3.0
FN;CHARSET=UTF-8:John Doe
N;CHARSET=UTF-8:Doe;John;;;
ORG;CHARSET=UTF-8:Acme Corp;Engineering
TEL;TYPE=WORK,VOICE:(111) 555-1212
EMAIL;TYPE=PREF,INTERNET:john.doe@example.com
END:VCARD

In src/converters/vcf.ts, TEL and EMAIL previously used .startsWith() to accommodate parameters, but FN, N, and ORG used strict equality:

if (key === "FN") { ... }
else if (key === "N") { ... }
else if (key === "ORG") { ... }

Because key captures the full token up to the colon ("FN;CHARSET=UTF-8"), these checks evaluated to false. Consequently, contact names and organizations were omitted, producing CSV rows with empty name fields.


Solution

  1. Base Property Name Extraction:
    Extract the primary property token before parameter delimiters:
    const prop = (key.split(";")[0] || "").trim().toUpperCase();
    
  2. Consistent Property Matching:
    Standardized FN, N, ORG, TEL, and EMAIL to match on prop. This properly handles arbitrary parameters (charsets, types, languages) while avoiding false matches on unrelated properties like NOTE or NICKNAME.

Changes

  • src/converters/vcf.ts: Normalize and extract base property names prior to matching.
  • tests/converters/vcf.test.ts: Added unit test verifying parameterized FN, N, ORG, TEL, and EMAIL cards convert to their respective CSV fields without data loss.

Verification

  • All 14 unit tests in tests/converters/vcf.test.ts pass cleanly.
  • Verified backward compatibility with standard, unparameterized vCards and CRLF line endings.
  • Verified no false positives against properties starting with N (NOTE, NICKNAME).

Summary by cubic

Fixes the VCF contact parser dropping FN, N, and ORG fields when they carry property parameters (e.g., CHARSET=UTF-8, LANGUAGE=en-US), so names and organizations from modern address book exports are no longer lost during conversion to CSV.

Bug Fixes

  • Extracts the base property name before parameter delimiters and matches on it for FN, N, ORG, TEL, and EMAIL.
  • Avoids false matches on similar properties like NOTE and NICKNAME.
  • Adds a unit test covering parameterized contact fields.