Repository navigation
fix(vcf): keep every phone, email and name when converting to CSV - #709
jayhemnani9910 wants to merge 2 commits into
Conversation
Each TEL or EMAIL overwrote the previous one, grouped properties like item1.EMAIL (iPhone) were skipped, N and FN with parameters (Android 2.1 exports) were dropped, quoted-printable values weren't decoded, folded long lines were cut at the fold, and \, \; escapes were left in or split on. Unfold lines, read the property name without group and parameters, join repeated phones and emails with "; ", decode quoted-printable values in their CHARSET, split N and ORG only on unescaped semicolons and undo text escapes.
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:17">
P2: `splitFields` treats a semicolon as escaped whenever its immediate predecessor is `\`, even when that backslash is itself escaped. For `N:Doe\\;Smith;John;;;`, this shifts `Smith` out of the first-name field; count consecutive preceding backslashes before splitting.</violation>
<violation number="2" location="src/converters/vcf.ts:21">
P2: Quoted vCard parameter values are not normalized, so `ENCODING="QUOTED-PRINTABLE"` remains undecoded and quoted non-UTF-8 charsets corrupt decoded names. Normalize optional quotes before matching encoding and charset parameters.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
|
|
||
| // vCard 2.1 parameters: "ENCODING=QUOTED-PRINTABLE" or a bare "QUOTED-PRINTABLE" | ||
| const isQuotedPrintable = (params: string[]) => | ||
| params.some((param) => /^(ENCODING=)?QUOTED-PRINTABLE$/i.test(param)); |
There was a problem hiding this comment.
P2: Quoted vCard parameter values are not normalized, so ENCODING="QUOTED-PRINTABLE" remains undecoded and quoted non-UTF-8 charsets corrupt decoded names. Normalize optional quotes before matching encoding and charset parameters.
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 21:
<comment>Quoted vCard parameter values are not normalized, so `ENCODING="QUOTED-PRINTABLE"` remains undecoded and quoted non-UTF-8 charsets corrupt decoded names. Normalize optional quotes before matching encoding and charset parameters.</comment>
<file context>
@@ -9,6 +9,32 @@ export const properties = {
+
+// vCard 2.1 parameters: "ENCODING=QUOTED-PRINTABLE" or a bare "QUOTED-PRINTABLE"
+const isQuotedPrintable = (params: string[]) =>
+ params.some((param) => /^(ENCODING=)?QUOTED-PRINTABLE$/i.test(param));
+
+// vCard 2.1 exports (Android) write non-ASCII values as quoted-printable bytes in CHARSET
</file context>
| value.replace(/\\([,;\\nN])/g, (_, c) => (c === "n" || c === "N" ? "\n" : c)); | ||
|
|
||
| // Split a structured value (N, ORG) on the ";" separators, not on escaped "\;" | ||
| const splitFields = (value: string) => value.split(/(?<!\\);/); |
There was a problem hiding this comment.
P2: splitFields treats a semicolon as escaped whenever its immediate predecessor is \, even when that backslash is itself escaped. For N:Doe\\;Smith;John;;;, this shifts Smith out of the first-name field; count consecutive preceding backslashes before splitting.
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 17:
<comment>`splitFields` treats a semicolon as escaped whenever its immediate predecessor is `\`, even when that backslash is itself escaped. For `N:Doe\\;Smith;John;;;`, this shifts `Smith` out of the first-name field; count consecutive preceding backslashes before splitting.</comment>
<file context>
@@ -9,6 +9,32 @@ export const properties = {
+ value.replace(/\\([,;\\nN])/g, (_, c) => (c === "n" || c === "N" ? "\n" : c));
+
+// Split a structured value (N, ORG) on the ";" separators, not on escaped "\;"
+const splitFields = (value: string) => value.split(/(?<!\\);/);
+
+// vCard 2.1 parameters: "ENCODING=QUOTED-PRINTABLE" or a bare "QUOTED-PRINTABLE"
</file context>
| const splitFields = (value: string) => value.split(/(?<!\\);/); | |
| const splitFields = (value: string) => { | |
| const fields = [""]; | |
| let backslashes = 0; | |
| for (const char of value) { | |
| if (char === "\\") { | |
| fields[fields.length - 1] += char; | |
| backslashes++; | |
| } else if (char === ";" && backslashes % 2 === 0) { | |
| fields.push(""); | |
| backslashes = 0; | |
| } else { | |
| fields[fields.length - 1] += char; | |
| backslashes = 0; | |
| } | |
| } | |
| return fields; | |
| }; |
|
looks good! just check the ai feedback |
Decode each field after splitting, so an encoded "=3B" stays in the
field instead of acting as a separator. Split on a semicolon after an
escaped backslash ("\;"), accept quoted parameter values like
ENCODING="QUOTED-PRINTABLE", and test that repeated emails are joined.
|
Thanks! I went through the review comments, all fixed in 352715f:
New test for the last three fails before and passes after. |
Converting a contacts export to CSV loses data. With three cards in the shapes iPhone, Google and Android contacts export write (contacts.vcf.txt):
TELandEMAILoverwrote the previous one, so only the last of each was kept. They are now joined with;.item1.EMAIL(iPhone writes custom-labelled fields with a group prefix) didn't matchstartsWith("EMAIL"). The property name is now read without the group and parameters.N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:...(Android's 2.1 export for any non-ASCII name) didn't matchkey === "N", and quoted-printable values weren't decoded. Both are handled now, including=soft line breaks on quoted-printable lines.\,,\;,\\and\nescapes are undone, andN/ORGare split only on unescaped;(N:Doe\;Smith;Johnis LastDoe;Smith, FirstJohn).CHARSET(UTF-8 if none), and a bareQUOTED-PRINTABLEparameter (vCard 2.1) is accepted too.Several phones or emails go into one cell, joined with
;, to keep one row per contact with the same columns. If you'd rather have extra columns (Phone 2, ...) I can change that.Four new cases in
tests/converters/vcf.test.tsfail before the change; one also has a base64PHOTOline ending in==next to aTEL, to make sure only quoted-printable lines are joined.bun test(non-integration): 464 passed. The 5 failures (archive route, production info, converter discovery) fail the same way on main here.eslint,prettier --checkandtscare clean for the changed files.Summary by cubic
Fixes VCF to CSV conversion dropping data when contacts have multiple phones, emails, or non-ASCII names.
TELandEMAILfields are now joined with;instead of overwriting the previous value.item1.EMAIL, folded continuation lines, and Android 2.1 styleCHARSET/QUOTED-PRINTABLEvalues with charset decoding, including quoted parameter values likeENCODING="QUOTED-PRINTABLE".\,,\;,\\, and\nescapes and splitsN/ORGonly on unescaped semicolons; fields are decoded after splitting so an encoded=3Bisn't taken as a separator.One row per contact with the same columns as before; multiple phone numbers or emails share a cell.
Written for commit 352715f. Summary will update on new commits.