Skip to content

fix(vcf): handle vCard properties with parameters - #727

Open
codeCraft-Ritik wants to merge 1 commit into
C4illin:mainfrom
codeCraft-Ritik:fix/vcf-parameter-parsing
Open

codeCraft-Ritik wants to merge 1 commit into
C4illin:mainfrom
codeCraft-Ritik:fix/vcf-parameter-parsing

Conversation

@codeCraft-Ritik

@codeCraft-Ritik codeCraft-Ritik commented Nov 23, 2026 •

Copy link
Copy Markdown

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.

Written for commit 02ff0c9. Summary will update on new commits.

View guided diff

@github-actions github-actions Bot added the Fix label Nov 23, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/converters/vcf.ts">

<violation number="1" location="src/converters/vcf.ts:28">
P1: The normalizer strips parameters but not the optional vCard group prefix, so common lines such as `item1.EMAIL;TYPE=HOME:` are still ignored. Extract the property name after the group separator before matching.</violation>

<violation number="2" location="src/converters/vcf.ts:28">
P2: Parameterized values containing a quoted colon are corrupted because the parser finds the first `:` before this new property matching runs. Find the delimiter outside quoted parameter values so lines such as `FN;X-INFO="a:b":John Doe` preserve `John Doe`.</violation>
</file>

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

Comment thread src/converters/vcf.ts
const key = line.slice(0, colonIndex).trim();
const value = line.slice(colonIndex + 1).trim();
if (key === "FN") {
const prop = (key.split(";")[0] || "").trim().toUpperCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The normalizer strips parameters but not the optional vCard group prefix, so common lines such as item1.EMAIL;TYPE=HOME: are still ignored. Extract the property name after the group separator before matching.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/converters/vcf.ts, line 28:

<comment>The normalizer strips parameters but not the optional vCard group prefix, so common lines such as `item1.EMAIL;TYPE=HOME:` are still ignored. Extract the property name after the group separator before matching.</comment>

<file context>
@@ -25,17 +25,19 @@ export function parseVCF(data: string): Record<string, string>[] {
         const key = line.slice(0, colonIndex).trim();
         const value = line.slice(colonIndex + 1).trim();
-        if (key === "FN") {
+        const prop = (key.split(";")[0] || "").trim().toUpperCase();
+
+        if (prop === "FN") {
</file context>
Suggested change
const prop = (key.split(";")[0] || "").trim().toUpperCase();
const prop = (key.split(";")[0]?.split(".").pop() || "").trim().toUpperCase();

Comment thread src/converters/vcf.ts
const key = line.slice(0, colonIndex).trim();
const value = line.slice(colonIndex + 1).trim();
if (key === "FN") {
const prop = (key.split(";")[0] || "").trim().toUpperCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Parameterized values containing a quoted colon are corrupted because the parser finds the first : before this new property matching runs. Find the delimiter outside quoted parameter values so lines such as FN;X-INFO="a:b":John Doe preserve John Doe.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/converters/vcf.ts, line 28:

<comment>Parameterized values containing a quoted colon are corrupted because the parser finds the first `:` before this new property matching runs. Find the delimiter outside quoted parameter values so lines such as `FN;X-INFO="a:b":John Doe` preserve `John Doe`.</comment>

<file context>
@@ -25,17 +25,19 @@ export function parseVCF(data: string): Record<string, string>[] {
         const key = line.slice(0, colonIndex).trim();
         const value = line.slice(colonIndex + 1).trim();
-        if (key === "FN") {
+        const prop = (key.split(";")[0] || "").trim().toUpperCase();
+
+        if (prop === "FN") {
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant