Repository navigation
fix(vcf): handle vCard properties with parameters - #727
Open
codeCraft-Ritik wants to merge 1 commit into
Open
codeCraft-Ritik wants to merge 1 commit into
codeCraft-Ritik wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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
| const key = line.slice(0, colonIndex).trim(); | ||
| const value = line.slice(colonIndex + 1).trim(); | ||
| if (key === "FN") { | ||
| const prop = (key.split(";")[0] || "").trim().toUpperCase(); |
Contributor
There was a problem hiding this comment.
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(); |
| const key = line.slice(0, colonIndex).trim(); | ||
| const value = line.slice(colonIndex + 1).trim(); | ||
| if (key === "FN") { | ||
| const prop = (key.split(";")[0] || "").trim().toUpperCase(); |
Contributor
There was a problem hiding this comment.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an issue in the VCF (vCard) contact parser where
FN(Full Name),N(Name), andORG(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:
In
src/converters/vcf.ts,TELandEMAILpreviously used.startsWith()to accommodate parameters, butFN,N, andORGused strict equality:Because
keycaptures the full token up to the colon ("FN;CHARSET=UTF-8"), these checks evaluated tofalse. Consequently, contact names and organizations were omitted, producing CSV rows with empty name fields.Solution
Extract the primary property token before parameter delimiters:
Standardized
FN,N,ORG,TEL, andEMAILto match onprop. This properly handles arbitrary parameters (charsets, types, languages) while avoiding false matches on unrelated properties likeNOTEorNICKNAME.Changes
src/converters/vcf.ts: Normalize and extract base property names prior to matching.tests/converters/vcf.test.ts: Added unit test verifying parameterizedFN,N,ORG,TEL, andEMAILcards convert to their respective CSV fields without data loss.Verification
tests/converters/vcf.test.tspass cleanly.N(NOTE,NICKNAME).Summary by cubic
Fixes the VCF contact parser dropping
FN,N, andORGfields 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
FN,N,ORG,TEL, andEMAIL.NOTEandNICKNAME.Written for commit 02ff0c9. Summary will update on new commits.