From 31b41dbd37c3694b3ffc3b7de2c3242a05e2bb63 Mon Sep 17 00:00:00 2001 From: MiMoHo <37556964+MiMoHo@users.noreply.github.com> Date: Fri, 3 Jul 2026 20:59:28 +0200 Subject: [PATCH] fix: trim vCard name fields on import to fix mis-sorting VcfImporter stored structured-name components verbatim from ezvcard, so a vCard whose given-name field had a leading space was imported as " John". normalizeString() strips only diacritics (not whitespace), and compareUsingStrings orders any value whose first character is not a letter after all A-Z names, filing the contact after "Z". The contact editor already trims these fields via the commons EditText.value extension; this matches that behavior by trimming the structured-name components at import, fixing sorting, the fast-scroll bubble, and business-contact detection. --- CHANGELOG.md | 3 +++ .../org/fossify/contacts/helpers/VcfImporter.kt | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9a92d320..50875c220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fixed contacts imported from vCard files being mis-sorted (filed after "Z") when their name fields contained leading or trailing whitespace ([#195]) ## [1.6.0] - 2026-01-30 ### Added @@ -119,6 +121,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#30]: https://github.com/FossifyOrg/Contacts/issues/30 [#78]: https://github.com/FossifyOrg/Contacts/issues/78 [#157]: https://github.com/FossifyOrg/Contacts/issues/157 +[#195]: https://github.com/FossifyOrg/Contacts/issues/195 [#201]: https://github.com/FossifyOrg/Contacts/issues/201 [#281]: https://github.com/FossifyOrg/Contacts/issues/281 [#289]: https://github.com/FossifyOrg/Contacts/issues/289 diff --git a/app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt b/app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt index d966813d9..4703f6aee 100644 --- a/app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt @@ -54,12 +54,12 @@ class VcfImporter(val activity: SimpleActivity) { val ezContacts = Ezvcard.parse(inputStream).all() for (ezContact in ezContacts) { val structuredName = ezContact.structuredName - val prefix = structuredName?.prefixes?.firstOrNull() ?: "" - val firstName = structuredName?.given ?: "" - val middleName = structuredName?.additionalNames?.firstOrNull() ?: "" - val surname = structuredName?.family ?: "" - val suffix = structuredName?.suffixes?.firstOrNull() ?: "" - val nickname = ezContact.nickname?.values?.firstOrNull() ?: "" + val prefix = structuredName?.prefixes?.firstOrNull()?.trim() ?: "" + val firstName = structuredName?.given?.trim() ?: "" + val middleName = structuredName?.additionalNames?.firstOrNull()?.trim() ?: "" + val surname = structuredName?.family?.trim() ?: "" + val suffix = structuredName?.suffixes?.firstOrNull()?.trim() ?: "" + val nickname = ezContact.nickname?.values?.firstOrNull()?.trim() ?: "" var photoUri = "" val phoneNumbers = ArrayList()