Skip to content

fix: remove stray space before suffix in contact display name#359

Closed
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/issue-157
Closed

fix: remove stray space before suffix in contact display name#359
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/issue-157

Conversation

@MiMoHo

@MiMoHo MiMoHo commented Jul 3, 2026

Copy link
Copy Markdown

Type of change(s)

  • Bug fix

What changed and why

Contact.getNameToDisplay() built the display name as listOfNotNull(prefix, firstPart, "$lastPart$suffixComma").filter { it.isNotBlank() }.joinToString(" "). The .filter { isNotBlank() } already fixed the double space from an empty middle part (e.g. prefix + surname only), but when the last name is empty and a suffix is present, the third element becomes ", <suffix>" — which is not blank, so it survives the filter and joinToString(" ") prepends a stray space, e.g. John , Jr / Smith , Jr.

Fix: make lastPart its own filterable element and append the suffix after the join, so an empty last name is dropped and the suffix comma is never preceded by a stray space.

This lives in commons because getNameToDisplay() is shared; it fixes the display name in Fossify Contacts and Phone (contact rows, details header, shortcuts, letter avatars).

Tests performed

Verified the pure getNameToDisplay() string logic against the reported and adjacent cases (before → after):

  • John + suffix Jr: John , JrJohn, Jr
  • start-with-surname Smith + suffix Jr: Smith , JrSmith, Jr
  • prefix Dr + surname Smith: Dr Smith (unchanged)
  • full Dr John Smith Jr: Dr John Smith, Jr (unchanged)

./gradlew :commons:detekt :commons:lintRelease :commons:assembleRelease all pass locally. (commons has no unit-test source set, so this is a static/logic verification.)

Related issue(s)

Checklist

  • I read the contribution guidelines.
  • I manually verified the affected logic.
  • I have self-reviewed my pull request.
  • I understand every change in this pull request.

Coded with Opus 4.8 ultracode.

getNameToDisplay() glued the suffix's leading ", " onto the last name inside a single list element ("$lastPart$suffixComma"). When the last name was empty, that element was non-blank (", <suffix>"), so the isNotBlank() filter kept it and joinToString(" ") prepended a stray space before the comma (e.g. "John , Jr", "Smith , Jr", "Dr , Jr").

Make lastPart its own filterable list element and append the suffix comma after the join, so an empty last name is dropped and the suffix comma is never preceded by a stray space. Fixes FossifyOrg/Contacts#157.
@MiMoHo MiMoHo requested a review from naveensingh as a code owner July 3, 2026 19:49
@MiMoHo MiMoHo closed this Jul 3, 2026
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.

Wrong spacing between prefix and last name

1 participant