Skip to content

Commit 446a74d

Browse files
rfc2822sunkup
andauthored
Fix vCard4 phone number processing for URI type (#180)
- Remove redundant null/blank checks for Telephone and Email properties - Add test case for URI type telephone numbers Co-authored-by: Sunik Kupfer <kupfer@bitfire.at>
1 parent a2eada8 commit 446a74d

2 files changed

Lines changed: 45 additions & 8 deletions

File tree

lib/src/main/kotlin/at/bitfire/vcard4android/ContactReader.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,9 @@ class ContactReader internal constructor(val vCard: VCard, val downloader: Conta
199199
c.jobDescription = prop.value?.trimToNull()
200200

201201
is Telephone ->
202-
if (!prop.text.isNullOrBlank())
203-
c.phoneNumbers += LabeledProperty(prop, findAndRemoveLabel(prop.group))
202+
c.phoneNumbers += LabeledProperty(prop, findAndRemoveLabel(prop.group))
204203
is Email ->
205-
if (!prop.value.isNullOrBlank())
206-
c.emails += LabeledProperty(prop, findAndRemoveLabel(prop.group))
204+
c.emails += LabeledProperty(prop, findAndRemoveLabel(prop.group))
207205
is Impp ->
208206
c.impps += LabeledProperty(prop, findAndRemoveLabel(prop.group))
209207
is XSip ->

lib/src/test/kotlin/at/bitfire/vcard4android/ContactReaderTest.kt

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,50 @@
66

77
package at.bitfire.vcard4android
88

9-
import at.bitfire.vcard4android.property.*
9+
import at.bitfire.vcard4android.property.CustomType
10+
import at.bitfire.vcard4android.property.XAbDate
11+
import at.bitfire.vcard4android.property.XAbLabel
12+
import at.bitfire.vcard4android.property.XAbRelatedNames
13+
import at.bitfire.vcard4android.property.XAddressBookServerKind
14+
import at.bitfire.vcard4android.property.XPhoneticFirstName
15+
import at.bitfire.vcard4android.property.XPhoneticLastName
16+
import at.bitfire.vcard4android.property.XPhoneticMiddleName
17+
import at.bitfire.vcard4android.property.XSip
1018
import ezvcard.VCard
1119
import ezvcard.VCardVersion
1220
import ezvcard.parameter.ImageType
1321
import ezvcard.parameter.RelatedType
1422
import ezvcard.parameter.SoundType
15-
import ezvcard.property.*
23+
import ezvcard.property.Address
24+
import ezvcard.property.Anniversary
25+
import ezvcard.property.Birthday
26+
import ezvcard.property.Categories
27+
import ezvcard.property.FormattedName
28+
import ezvcard.property.Impp
29+
import ezvcard.property.Kind
30+
import ezvcard.property.Label
31+
import ezvcard.property.Logo
32+
import ezvcard.property.Member
33+
import ezvcard.property.Nickname
34+
import ezvcard.property.Organization
35+
import ezvcard.property.Photo
36+
import ezvcard.property.ProductId
37+
import ezvcard.property.RawProperty
38+
import ezvcard.property.Related
39+
import ezvcard.property.Revision
40+
import ezvcard.property.SortString
41+
import ezvcard.property.Sound
42+
import ezvcard.property.StructuredName
43+
import ezvcard.property.Telephone
44+
import ezvcard.property.Uid
45+
import ezvcard.property.Url
1646
import ezvcard.util.PartialDate
17-
import org.junit.Assert.*
47+
import ezvcard.util.TelUri
48+
import org.junit.Assert.assertArrayEquals
49+
import org.junit.Assert.assertEquals
50+
import org.junit.Assert.assertFalse
51+
import org.junit.Assert.assertNull
52+
import org.junit.Assert.assertTrue
1853
import org.junit.Test
1954
import java.net.URI
2055
import java.time.LocalDate
@@ -366,9 +401,13 @@ class ContactReaderTest {
366401
@Test
367402
fun testTelephone() {
368403
val c = ContactReader.fromVCard(VCard().apply {
404+
// number of type TEXT
369405
addTelephoneNumber("+1 555 12345")
406+
// number of type URI
407+
addTelephoneNumber(Telephone(TelUri.parse("tel:123")))
370408
})
371-
assertEquals("+1 555 12345", c.phoneNumbers.first.property.text)
409+
assertEquals("+1 555 12345", c.phoneNumbers[0].property.text)
410+
assertEquals("123", c.phoneNumbers[1].property.uri.number)
372411
}
373412

374413

0 commit comments

Comments
 (0)