Commit 8d3adfa4 authored by Lucio Maciel's avatar Lucio Maciel Committed by GitHub

Merge pull request #392 from RocketChat/fix/crash_on_building_default_avatar

Fix crash when building default avatar 
parents 6fc6e16e 1795b974
......@@ -69,8 +69,11 @@ object UserAvatarHelper {
}
val splitUsername = username.split(".")
if (splitUsername.size > 1) {
return (splitUsername[0].substring(0, 1) + splitUsername[splitUsername.size - 1].substring(0, 1)).toUpperCase()
val splitCount = splitUsername.size
if (splitCount > 1 && splitUsername[0].isNotEmpty() && splitUsername[1].isNotEmpty()) {
val firstInitial = splitUsername[0].substring(0, 1)
val secondInitial = splitUsername[1].substring(0, 1)
return (firstInitial + secondInitial).toUpperCase()
} else {
if (username.length > 1) {
return username.substring(0, 2).toUpperCase()
......
......@@ -18,5 +18,9 @@ class UserAvatarHelperTest {
assert(UserAvatarHelper.getUsernameInitials("Foo.bar") == "FB")
assert(UserAvatarHelper.getUsernameInitials("Foobar.bar") == "FB")
assert(UserAvatarHelper.getUsernameInitials("Foobar.bar.zab") == "FZ")
assert(UserAvatarHelper.getUsernameInitials("..") == "..")
assert(UserAvatarHelper.getUsernameInitials("...") == "..")
assert(UserAvatarHelper.getUsernameInitials(".Foo.") == ".F")
assert(UserAvatarHelper.getUsernameInitials("Foo..") == "FO")
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment