@@ -21,23 +21,28 @@ internal class VCard private constructor(
2121 val lastName = lastName.orEmpty()
2222 val nickname = nickname.orEmpty()
2323 if (firstName.isNotEmpty() || lastName.isNotEmpty()) {
24- contentBuilder.append(" N:$lastName ;$firstName ;;;\n " )
25- .append(" FN:${(" $firstName $lastName " .trim()).ifEmpty { nickname }} \n " )
24+ contentBuilder.append(" N:${lastName.escaped()} ;${firstName.escaped()} ;;;\n " )
25+ .append(
26+ " FN:${(" ${firstName.escaped()} ${lastName.escaped()} " .trim()).ifEmpty { nickname.escaped() }} \n "
27+ )
2628 }
27- val calculatedNickname = nickname.ifEmpty { " $firstName $lastName " .trim() }
29+ val calculatedNickname = nickname.ifEmpty { " $firstName $lastName " .trim() }.escaped()
2830
29- calculatedNickname.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" NICKNAME:$it \n " ) }
30- organization?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" ORG:$it \n " ) }
31- title?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" TITLE:$it \n " ) }
32- profileUrl?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" URL:$it \n " ) }
33- note?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" NOTE:$it \n " ) }
34- phoneNumber?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" TEL;TYPE=cell:$it \n " ) }
35- email?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" EMAIL:$it \n " ) }
31+ calculatedNickname.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" NICKNAME:${it.escaped()} \n " ) }
32+ organization?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" ORG:${it.escaped()} \n " ) }
33+ title?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" TITLE:${it.escaped()} \n " ) }
34+ profileUrl?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" URL:${it.escaped()} \n " ) }
35+ note?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" NOTE:${it.escaped()} \n " ) }
36+ phoneNumber?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" TEL;TYPE=cell:${it.escaped()} \n " ) }
37+ email?.takeIf { it.isNotEmpty() }?.let { contentBuilder.append(" EMAIL:${it.escaped()} \n " ) }
3638
3739 contentBuilder.append(" END:VCARD" )
3840 return contentBuilder.toString()
3941 }
4042
43+ // We've seen issues with newlines in the vCard content causing problems when importing the contact so removing them
44+ private fun String.escaped () = this .replace(" \n " , " " )
45+
4146 class Builder (
4247 private var firstName : String? = null ,
4348 private var lastName : String? = null ,
0 commit comments