Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 4581d0ae authored by Ricki Hirner's avatar Ricki Hirner Committed by GitHub
Browse files

Parse (X-ADDRESSBOOKSERVER-)KIND:GROUP value case-insensitively (#21)

parent bd082066
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import java.time.LocalDateTime
import java.time.OffsetDateTime
import java.time.temporal.ChronoField
import java.time.temporal.Temporal
import java.util.*
import java.util.UUID
import java.util.logging.Level

/**
@@ -125,13 +125,12 @@ class ContactReader internal constructor(val vCard: VCard, val downloader: Conta
                is Uid ->
                    c.uid = uriToUid(prop.value)

                is Kind, is XAddressBookServerKind -> {
                    val kindProp = prop as Kind
                    c.group = kindProp.isGroup
                is Kind -> {        // includes XAddressBookServerKind
                    // c.group = prop.isGroup    // https://github.com/mangstadt/ez-vcard/issues/140
                    c.group = prop.value.equals(Kind.GROUP, true)
                }
                is Member, is XAddressBookServerMember -> {
                    val uriProp = prop as Member
                    uriToUid(uriProp.uri)?.let { c.members += it }
                is Member -> {      // includes XAddressBookServerMember
                    uriToUid(prop.uri)?.let { c.members += it }
                }

                is FormattedName ->
+8 −0
Original line number Diff line number Diff line
@@ -139,6 +139,14 @@ class ContactReaderTest {
        assertTrue(c.group)
    }

    @Test
    fun testKind_Group_Uppercase() {
        val c = ContactReader.fromVCard(VCard().apply {
            kind = Kind("GROUP")
        })
        assertTrue(c.group)
    }

    @Test
    fun testKind_Individual() {
        val c = ContactReader.fromVCard(VCard().apply {
+1 −7
Original line number Diff line number Diff line
@@ -35,12 +35,6 @@ class ContactTest {
        return Contact.fromReader(InputStreamReader(ByteArrayInputStream(os.toByteArray()), Charsets.UTF_8), false,null).first()
    }

    private fun toString(c: Contact, groupMethod: GroupMethod, vCardVersion: VCardVersion): String {
        val os = ByteArrayOutputStream()
        c.writeVCard(vCardVersion, os)
        return os.toString()
    }


    @Test
    fun testVCard3FieldsAsVCard3() {
+11 −4
Original line number Diff line number Diff line
@@ -8,14 +8,21 @@ import ezvcard.Ezvcard
import ezvcard.VCard
import ezvcard.VCardVersion
import ezvcard.property.Address
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Assert.*
import org.junit.Test
import java.util.*

class EzVCardTest {

    // https://github.com/mangstadt/ez-vcard/issues/140
    @Test(expected = AssertionError::class)
    fun testKind_GROUP_uppercase() {
        val vCard = Ezvcard.parse("BEGIN:VCARD\r\n" +
                "VERSION:4.0\r\n" +
                "KIND:GROUP\r\n" +
                "END:VCARD").first()
        assertTrue(vCard.kind.isGroup)
    }

    @Test
    fun testREV_UTC() {
        val vCard = Ezvcard.parse("BEGIN:VCARD\r\n" +