From 5b91047b5db676a7c099905865398ddf94d99076 Mon Sep 17 00:00:00 2001 From: Sunik Kupfer Date: Mon, 2 Feb 2026 14:19:25 +0100 Subject: [PATCH] Fix vCard4 phone number processing for URI type - Remove redundant null/blank checks for Telephone and Email properties - Add test case for URI type telephone numbers --- .../at/bitfire/vcard4android/ContactReader.kt | 6 +-- .../vcard4android/ContactReaderTest.kt | 47 +++++++++++++++++-- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/lib/src/main/kotlin/at/bitfire/vcard4android/ContactReader.kt b/lib/src/main/kotlin/at/bitfire/vcard4android/ContactReader.kt index 76ff0569..cc3dfbb0 100644 --- a/lib/src/main/kotlin/at/bitfire/vcard4android/ContactReader.kt +++ b/lib/src/main/kotlin/at/bitfire/vcard4android/ContactReader.kt @@ -199,11 +199,9 @@ class ContactReader internal constructor(val vCard: VCard, val downloader: Conta c.jobDescription = prop.value?.trimToNull() is Telephone -> - if (!prop.text.isNullOrBlank()) - c.phoneNumbers += LabeledProperty(prop, findAndRemoveLabel(prop.group)) + c.phoneNumbers += LabeledProperty(prop, findAndRemoveLabel(prop.group)) is Email -> - if (!prop.value.isNullOrBlank()) - c.emails += LabeledProperty(prop, findAndRemoveLabel(prop.group)) + c.emails += LabeledProperty(prop, findAndRemoveLabel(prop.group)) is Impp -> c.impps += LabeledProperty(prop, findAndRemoveLabel(prop.group)) is XSip -> diff --git a/lib/src/test/kotlin/at/bitfire/vcard4android/ContactReaderTest.kt b/lib/src/test/kotlin/at/bitfire/vcard4android/ContactReaderTest.kt index cd4534f7..f691f660 100644 --- a/lib/src/test/kotlin/at/bitfire/vcard4android/ContactReaderTest.kt +++ b/lib/src/test/kotlin/at/bitfire/vcard4android/ContactReaderTest.kt @@ -6,15 +6,50 @@ package at.bitfire.vcard4android -import at.bitfire.vcard4android.property.* +import at.bitfire.vcard4android.property.CustomType +import at.bitfire.vcard4android.property.XAbDate +import at.bitfire.vcard4android.property.XAbLabel +import at.bitfire.vcard4android.property.XAbRelatedNames +import at.bitfire.vcard4android.property.XAddressBookServerKind +import at.bitfire.vcard4android.property.XPhoneticFirstName +import at.bitfire.vcard4android.property.XPhoneticLastName +import at.bitfire.vcard4android.property.XPhoneticMiddleName +import at.bitfire.vcard4android.property.XSip import ezvcard.VCard import ezvcard.VCardVersion import ezvcard.parameter.ImageType import ezvcard.parameter.RelatedType import ezvcard.parameter.SoundType -import ezvcard.property.* +import ezvcard.property.Address +import ezvcard.property.Anniversary +import ezvcard.property.Birthday +import ezvcard.property.Categories +import ezvcard.property.FormattedName +import ezvcard.property.Impp +import ezvcard.property.Kind +import ezvcard.property.Label +import ezvcard.property.Logo +import ezvcard.property.Member +import ezvcard.property.Nickname +import ezvcard.property.Organization +import ezvcard.property.Photo +import ezvcard.property.ProductId +import ezvcard.property.RawProperty +import ezvcard.property.Related +import ezvcard.property.Revision +import ezvcard.property.SortString +import ezvcard.property.Sound +import ezvcard.property.StructuredName +import ezvcard.property.Telephone +import ezvcard.property.Uid +import ezvcard.property.Url import ezvcard.util.PartialDate -import org.junit.Assert.* +import ezvcard.util.TelUri +import org.junit.Assert.assertArrayEquals +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue import org.junit.Test import java.net.URI import java.time.LocalDate @@ -366,9 +401,13 @@ class ContactReaderTest { @Test fun testTelephone() { val c = ContactReader.fromVCard(VCard().apply { + // number of type TEXT addTelephoneNumber("+1 555 12345") + // number of type URI + addTelephoneNumber(Telephone(TelUri.parse("tel:123"))) }) - assertEquals("+1 555 12345", c.phoneNumbers.first.property.text) + assertEquals("+1 555 12345", c.phoneNumbers[0].property.text) + assertEquals("123", c.phoneNumbers[1].property.uri.number) }