Skip to content

fix: trim vCard name fields on import to fix mis-sorting#574

Open
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/issue-195
Open

fix: trim vCard name fields on import to fix mis-sorting#574
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/issue-195

Conversation

@MiMoHo

@MiMoHo MiMoHo commented Jul 3, 2026

Copy link
Copy Markdown

Type of change(s)

  • Bug fix

What changed and why

VcfImporter stored the structured-name components (given, family, additionalNames, prefixes, suffixes) and the nickname verbatim from ezvcard, without trimming. A vCard whose given-name field has a leading space (e.g. N:Doe; John;;;) was therefore imported as firstName = " John".

That corrupts the sort key: Contact.compareTo builds it with firstName.normalizeString(), and normalizeString() only strips diacritics via NFD normalization, not whitespace. compareUsingStrings then deterministically orders any value whose first character is not a letter (a leading space; ' '.isLetter() == false) after every A-Z name, so the contact files at the very end, after "Z". The contact still displays as "John" because getNameToDisplay() trims, which is exactly the confusing symptom the reporter described. The fast-scroll bubble (getBubbleText(), which returns the raw first name) is affected too.

The contact editor already trims these fields when saving, through the commons EditText.value extension (text.toString().trim()). This change makes VCF import match that convention by applying ?.trim() to each structured-name component at import time. For a null component the safe-call short-circuits and the elvis yields "", so behavior is unchanged for absent fields; for " John" it yields "John". One place fixes sorting, the fast-scroll bubble, and business-contact detection.

Tests performed

Built the fossDebug variant and verified on an Android 15 (API 35) emulator:

Imported a vCard whose given name had a leading space (' John'); sorted by First name. 'John Doe' filed correctly under 'J' between 'Amy Adams' and 'Zack Zulu', avatar shows 'J', fast-scroll index shows A/J/Z (no blank / bottom placement). Name trimmed on import.

Also confirmed detekt, lint, unit tests and the build all pass locally (CI-equivalent).

Closes the following issue(s)

Checklist

  • I read the contribution guidelines.
  • I manually tested my changes on device/emulator.
  • I updated the "Unreleased" section in CHANGELOG.md (if applicable).
  • I have self-reviewed my pull request (no typos, formatting errors, etc.).
  • I understand every change in this pull request.

Coded with Opus 4.8 ultracode.

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.
@MiMoHo MiMoHo requested a review from naveensingh as a code owner July 3, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When First Name starts with White Space, the card is Filed at the End, after Z

1 participant