Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
9
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
bitfire web engineering
vcard4android
Commits
e4b70252
Commit
e4b70252
authored
Jan 05, 2021
by
Ricki Hirner
🐑
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nickname and Website URL: treat TYPE value as case-insensitive
parent
368898fc
Pipeline
#237548429
passed with stages
in 4 minutes and 50 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
29 deletions
+96
-29
src/androidTest/java/at/bitfire/vcard4android/AndroidContactTest.kt
...dTest/java/at/bitfire/vcard4android/AndroidContactTest.kt
+86
-20
src/main/java/at/bitfire/vcard4android/AndroidContact.kt
src/main/java/at/bitfire/vcard4android/AndroidContact.kt
+10
-9
No files found.
src/androidTest/java/at/bitfire/vcard4android/AndroidContactTest.kt
View file @
e4b70252
...
...
@@ -204,16 +204,17 @@ class AndroidContactTest {
}
@Test
@SmallTest
fun
testEmailTypes
()
{
val
vCard
=
"BEGIN:VCARD\r\n"
+
"VERSION:4.0\r\n"
+
"FN:Test\r\n"
+
"EMAIL;TYPE=internet;TYPE=work:work@example.com\r\n"
+
"EMAIL;TYPE=
home
:home@example.com\r\n"
+
"EMAIL;TYPE=
HOME
:home@example.com\r\n"
+
"EMAIL;TYPE=internet,pref:other1@example.com\r\n"
+
"EMAIL;TYPE=x400,o
th
er:other2@example.com\r\n"
+
"EMAIL;TYPE=x400,o
TH
er:other2@example.com\r\n"
+
"EMAIL;TYPE=x-mobile:mobile@example.com\r\n"
+
"group1.EMAIL;TYPE=x-with-label:withlabel@example.com\r\n"
+
"group1.X-ABLABEL:With label and x-type\r\n"
+
"END:VCARD\r\n"
val
contacts
=
Contact
.
fromReader
(
StringReader
(
vCard
),
null
)
...
...
@@ -223,25 +224,89 @@ class AndroidContactTest {
val
dbContact2
=
addressBook
.
findContactByID
(
dbContact
.
id
!!
)
try
{
val
contact2
=
dbContact2
.
contact
!!
assertEquals
(
"work@example.com"
,
contact2
.
emails
[
0
].
property
.
value
)
assertArrayEquals
(
arrayOf
(
EmailType
.
WORK
),
contact2
.
emails
[
0
].
property
.
types
.
toTypedArray
())
assertNull
(
contact2
.
emails
[
0
].
property
.
pref
)
assertEquals
(
"home@example.com"
,
contact2
.
emails
[
1
].
property
.
value
)
assertArrayEquals
(
arrayOf
(
EmailType
.
HOME
),
contact2
.
emails
[
1
].
property
.
types
.
toTypedArray
())
assertNull
(
contact2
.
emails
[
1
].
property
.
pref
)
assertEquals
(
6
,
contact2
.
emails
.
size
)
contact2
.
emails
[
0
].
property
.
let
{
email
->
assertEquals
(
"work@example.com"
,
email
.
value
)
assertArrayEquals
(
arrayOf
(
EmailType
.
WORK
),
email
.
types
.
toTypedArray
())
assertNull
(
email
.
pref
)
}
contact2
.
emails
[
1
].
property
.
let
{
email
->
assertEquals
(
"home@example.com"
,
email
.
value
)
assertArrayEquals
(
arrayOf
(
EmailType
.
HOME
),
email
.
types
.
toTypedArray
())
assertNull
(
email
.
pref
)
}
contact2
.
emails
[
2
].
property
.
let
{
email
->
assertEquals
(
"other1@example.com"
,
email
.
value
)
assertTrue
(
email
.
types
.
isEmpty
())
assertNotEquals
(
0
,
email
.
pref
)
}
contact2
.
emails
[
3
].
property
.
let
{
email
->
assertEquals
(
"other2@example.com"
,
email
.
value
)
assertTrue
(
email
.
types
.
isEmpty
())
assertNull
(
email
.
pref
)
}
contact2
.
emails
[
4
].
property
.
let
{
email
->
assertEquals
(
"mobile@example.com"
,
email
.
value
)
assertArrayEquals
(
arrayOf
(
Contact
.
EMAIL_TYPE_MOBILE
),
email
.
types
.
toTypedArray
())
assertNull
(
email
.
pref
)
}
contact2
.
emails
[
5
].
let
{
email
->
assertEquals
(
"withlabel@example.com"
,
email
.
property
.
value
)
assertEquals
(
EmailType
.
get
(
"x-with-label-and-x-type"
),
email
.
property
.
types
.
first
())
assertEquals
(
"With label and x-type"
,
email
.
label
)
}
}
finally
{
dbContact2
.
delete
()
}
}
assertEquals
(
"other1@example.com"
,
contact2
.
emails
[
2
].
property
.
value
)
assertTrue
(
contact2
.
emails
[
2
].
property
.
types
.
isEmpty
())
assertNotEquals
(
0
,
contact2
.
emails
[
2
].
property
.
pref
)
@Test
fun
testWebsiteTypes
()
{
val
vCard
=
"BEGIN:VCARD\r\n"
+
"VERSION:4.0\r\n"
+
"FN:Test\r\n"
+
"URL;TYPE=home:http://home.example\r\n"
+
"URL;TYPE=WORK:http://WORK.example\r\n"
+
"URL;TYPE=Custom:http://Custom.example\r\n"
+
"group1.URL;TYPE=x-custom-with-label:http://Custom.example\r\n"
+
"group1.X-ABLABEL:Custom (with label)\r\n"
+
"END:VCARD\r\n"
val
contacts
=
Contact
.
fromReader
(
StringReader
(
vCard
),
null
)
assertEquals
(
"other2@example.com"
,
contact2
.
emails
[
3
].
property
.
value
)
assertTrue
(
contact2
.
emails
[
3
].
property
.
types
.
isEmpty
())
assertNull
(
contact2
.
emails
[
3
].
property
.
pref
)
val
dbContact
=
AndroidContact
(
addressBook
,
contacts
.
first
(),
null
,
null
)
dbContact
.
add
()
assertEquals
(
"mobile@example.com"
,
contact2
.
emails
[
4
].
property
.
value
)
assertArrayEquals
(
arrayOf
(
Contact
.
EMAIL_TYPE_MOBILE
),
contact2
.
emails
[
4
].
property
.
types
.
toTypedArray
())
assertNull
(
contact2
.
emails
[
4
].
property
.
pref
)
val
dbContact2
=
addressBook
.
findContactByID
(
dbContact
.
id
!!
)
try
{
val
contact2
=
dbContact2
.
contact
!!
assertEquals
(
4
,
contact2
.
urls
.
size
)
contact2
.
urls
[
0
].
property
.
let
{
url
->
assertEquals
(
"http://home.example"
,
url
.
value
)
assertEquals
(
"home"
,
url
.
type
)
}
contact2
.
urls
[
1
].
property
.
let
{
url
->
assertEquals
(
"http://WORK.example"
,
url
.
value
)
assertEquals
(
"work"
,
url
.
type
)
}
contact2
.
urls
[
2
].
property
.
let
{
url
->
assertEquals
(
"http://Custom.example"
,
url
.
value
)
assertEquals
(
"x-custom"
,
url
.
type
)
}
contact2
.
urls
[
3
].
let
{
url
->
assertEquals
(
"http://Custom.example"
,
url
.
property
.
value
)
assertEquals
(
"x-custom-with-label"
,
url
.
property
.
type
)
assertEquals
(
"Custom (with label)"
,
url
.
label
)
}
}
finally
{
dbContact2
.
delete
()
}
...
...
@@ -250,7 +315,7 @@ class AndroidContactTest {
@Test
fun
testLabelToXName
()
{
assertEquals
(
"
X-AUNTIES_HOME
"
,
AndroidContact
.
labelToXName
(
"auntie's home"
))
assertEquals
(
"
x-aunties-home
"
,
AndroidContact
.
labelToXName
(
"auntie's home"
))
}
@Test
...
...
@@ -262,6 +327,7 @@ class AndroidContactTest {
@Test
fun
testXNameToLabel
()
{
assertEquals
(
"Aunties Home"
,
AndroidContact
.
xNameToLabel
(
"X-AUNTIES-HOME"
))
assertEquals
(
"Aunties Home"
,
AndroidContact
.
xNameToLabel
(
"X-AUNTIES_HOME"
))
}
...
...
src/main/java/at/bitfire/vcard4android/AndroidContact.kt
View file @
e4b70252
...
...
@@ -52,18 +52,19 @@ open class AndroidContact(
const
val
COLUMN_UID
=
RawContacts
.
SYNC1
const
val
COLUMN_ETAG
=
RawContacts
.
SYNC2
fun
labelToXName
(
label
:
String
)
=
"
X
-"
+
label
.
replace
(
" "
,
"_"
)
fun
labelToXName
(
label
:
String
)
=
"
x
-"
+
label
.
replace
(
' '
,
'-'
)
.
replace
(
Regex
(
"[^\\p{L}\\p{Nd}\\-_]"
),
""
)
.
to
Upp
erCase
(
Locale
.
getDefault
()
)
.
to
Low
erCase
()
fun
xNameToLabel
(
xname
:
String
):
String
{
// "
X-MY_PROPERTY
"
// "
x-my_property
"
var
s
=
xname
.
toLowerCase
(
Locale
.
getDefault
())
// 1. ensure lower case -> "x-my_property"
if
(
s
.
startsWith
(
"x-"
))
// 2. remove x- from beginning -> "my_property"
if
(
s
.
startsWith
(
"x-"
))
// 2. remove x- from beginning -> "my_property"
s
=
s
.
substring
(
2
)
s
=
s
.
replace
(
'_'
,
' '
)
// 3. replace "_" by " " -> "my property"
return
WordUtils
.
capitalize
(
s
)
// 4. capitalize -> "My Property"
s
=
s
.
replace
(
'_'
,
' '
)
// 3. replace "_" and "-" by " " -> "my property"
.
replace
(
'-'
,
' '
)
return
WordUtils
.
capitalize
(
s
)
// 4. capitalize -> "My Property"
}
fun
toURIScheme
(
s
:
String
?)
=
...
...
@@ -916,7 +917,7 @@ open class AndroidContact(
val
typeCode
:
Int
var
typeLabel
:
String
?
=
null
val
type
=
nick
.
type
val
type
=
nick
.
type
?.
toLowerCase
()
typeCode
=
when
(
type
)
{
Contact
.
NICKNAME_TYPE_MAIDEN_NAME
->
Nickname
.
TYPE_MAIDEN_NAME
Contact
.
NICKNAME_TYPE_SHORT_NAME
->
Nickname
.
TYPE_SHORT_NAME
...
...
@@ -1019,7 +1020,7 @@ open class AndroidContact(
typeCode
=
Website
.
TYPE_CUSTOM
typeLabel
=
labeledUrl
.
label
}
else
{
val
type
=
url
.
type
val
type
=
url
.
type
?.
toLowerCase
()
typeCode
=
when
(
type
)
{
Contact
.
URL_TYPE_HOMEPAGE
->
Website
.
TYPE_HOMEPAGE
Contact
.
URL_TYPE_BLOG
->
Website
.
TYPE_BLOG
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment