Modern Apps git

← Modern-Apps.git

contacts: vCard import no longer drops group-prefixed properties

Commit
3686d09444d908719474d9b6d12b774f451bb68d
Author
Vayun Mathur <[email protected]>
When
2026-11-30 19:10 UTC (5 days ago)
Parents
63cbc85
Apple and other exporters emit grouped properties (item1.TEL,
item2.EMAIL, item3.ADR). The parser uppercased the full token and
dispatched on the result, so ITEM1.TEL matched nothing and grouped
lines were silently discarded: a card whose fields are all grouped
imported as a contact with no phone, email, address or birthday.

Group prefixes are now stripped (substringAfterLast('.')) before
dispatch, which also covers grouped FN/N/ORG/PHOTO/CATEGORIES;
grouped labels like item1.X-ABLabel stay ignored as before. New
regression test imports a grouped-only card and asserts all four
fields survive (failed pre-fix at the phone assertion); an existing
grouped test now asserts the grouped phone is retained. vCard
escaping, merge, search, group resolution and date parsing were
audited in the same pass. Verified: VcfParamsW5Test passes,
:contacts:lint passes; two failing compose/navigation tests also
fail on the untouched tree from other in-flight Route work.

Diff

contacts/src/main/java/com/vayunmathur/contacts/data/VcfParser.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/data/VcfParser.kt b/contacts/src/main/java/com/vayunmathur/contacts/data/VcfParser.ktindex 8151db3751..23ddbe4be6 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/data/VcfParser.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/data/VcfParser.kt@@ -120,7 +120,12 @@ private class VcfParser(         val valuePart = line.substring(colonIndex + 1)          val segments = nameAndParams.split(';')-        val propName = segments.firstOrNull()?.uppercase() ?: return+        // Group-prefixed properties ("item1.TEL", "item2.ADR", …) are how+        // Apple and other exporters attach related lines; the group name is+        // framing, not part of the property name. Strip it or every grouped+        // phone/email/address/date is silently dropped on import.+        val propName = segments.firstOrNull()?.uppercase()+            ?.substringAfterLast('.') ?: return         val params = parseParams(segments.drop(1))         val decodedValue = decodeValue(params, valuePart) 
contacts/src/test/java/com/vayunmathur/contacts/pure/VcfParamsW5Test.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/pure/VcfParamsW5Test.kt b/contacts/src/test/java/com/vayunmathur/contacts/pure/VcfParamsW5Test.ktindex 2ce70f79d7..35284e56e0 100644--- a/contacts/src/test/java/com/vayunmathur/contacts/pure/VcfParamsW5Test.kt+++ b/contacts/src/test/java/com/vayunmathur/contacts/pure/VcfParamsW5Test.kt@@ -29,13 +29,39 @@ class VcfParamsW5Test {         )         assertEquals(1, contacts.size)         val numbers = contacts[0].details.phoneNumbers.map { it.number }-        // Group-prefixed properties go through the param parser even when-        // the parser ultimately keeps only the ungrouped rows.-        assertTrue(numbers.isNotEmpty(), "phones should parse, got $numbers")+        assertTrue(numbers.contains("+14155550102"), "grouped phone should parse, got $numbers")         assertTrue(numbers.contains("+442071234567"), "quoted multi-type phone should parse, got $numbers")         assertEquals(listOf("[email protected]"), contacts[0].details.emails.map { it.address })     } +    @Test+    fun groupedOnlyPropertiesAreImported() {+        val contacts = parse(+            """+            BEGIN:VCARD+            VERSION:3.0+            FN:Grouped Only+            N:Only;Grouped;;;+            item1.TEL;TYPE=CELL:+14155550102+            item1.X-ABLabel:Mobile+            item2.EMAIL;TYPE=HOME:[email protected]+            item3.ADR;TYPE=HOME:;;1 Group Way;Springfield;IL;12345;US+            item4.BDAY:19900102+            END:VCARD+            """.trimIndent()+        )+        assertEquals(1, contacts.size)+        val contact = contacts[0]+        assertEquals(listOf("+14155550102"), contact.details.phoneNumbers.map { it.number })+        assertEquals(listOf("[email protected]"), contact.details.emails.map { it.address })+        assertEquals(1, contact.details.addresses.size)+        assertTrue(contact.details.addresses[0].formattedAddress.contains("1 Group Way"))+        assertEquals(+            listOf("1990-01-02"),+            contact.details.dates.map { it.startDate.toString() },+        )+    }+     @Test     fun charsetAndQuotedPrintableParams() {         val contacts = parse(