Skip to content

fix(desktop): derive avatar initials by character, not code unit - #5992

Open
Chessing234 wants to merge 2 commits into
block:mainfrom
Chessing234:fix/initials-astral-names
Open

fix(desktop): derive avatar initials by character, not code unit#5992
Chessing234 wants to merge 2 commits into
block:mainfrom
Chessing234:fix/initials-astral-names

Conversation

@Chessing234

Copy link
Copy Markdown
Contributor

Found by probing getInitials with non-Latin names; no issue filed. It feeds every avatar fallback in the app — UserAvatar, ProfileAvatar, IdentityInitialsAvatar, CommunityRail.

Two separate bugs, one commit each.

Half a surrogate pair. The function took part[0], a UTF-16 code unit. A name whose first letter lives outside the Basic Multilingual Plane is a surrogate pair, so that returned half of one — not a character:

"𠀀明"          →  "\ud840"      (a lone high surrogate, renders as �)
"𝐀da Lovelace" →  "\ud835L"

CJK Extension B appears in ordinary Chinese and Japanese given names, so every avatar for such a person rendered . Now iterating code points, and taking two of them before joining rather than slicing two code units off the result, so the second initial can't be halved either.

A word cut in half at a combining mark. Marks are neither \p{L} nor \p{N}, so they were replaced with a separator — cutting words apart from the inside:

name before after
अनिल कुमार अल अक
नमस्ते नत
မောင်မောင် မင

"अनिल कुमार" split at the vowel sign into "अन" and "ल", so both initials came from the middle of the first name and the surname was never reached; a one-word name produced two initials where there is one word to initial. Devanagari, Burmese, Thai and Khmer names take marks in ordinary spelling. \p{M} is now kept alongside letters and numbers — punctuation is still stripped, and the existing "B (relay)" → "BR" case is pinned by a test in both commits.

Verified locally at this head:

  • pnpm test4961 passed, 0 failed (4954 before, plus the 7 new)
  • pnpm check — clean; its 2 warnings and 2 infos are pre-existing and identical on main
  • pnpm build — succeeded

Note: I'm an outside contributor, so the workflow runs here sit at action_required until a maintainer approves them; only the DCO check reports on its own.

`getInitials` took `part[0]`, a UTF-16 code unit. A name whose first letter
lives outside the Basic Multilingual Plane is a surrogate pair, so that
returned half of one — not a character. CJK Extension B appears in ordinary
Chinese and Japanese given names, and every avatar for such a person rendered
`�`.

Iterate code points, and take two of them before joining rather than slicing
two code units off the result, so the second initial cannot be halved either.

Signed-off-by: Taksh <takshkothari09@gmail.com>
Combining marks are neither `\p{L}` nor `\p{N}`, so `getInitials` replaced
them with a separator and cut words apart from the inside. "अनिल कुमार" split
at the vowel sign into "अन" and "ल", producing "अल" — two letters from the
middle of the first name, with the surname never reached. A one-word name
like "नमस्ते" produced two initials where there is one word to initial.
Devanagari, Burmese, Thai and Khmer names take marks in ordinary spelling.

Keep `\p{M}` alongside letters and numbers. Punctuation is still stripped, so
"B (relay)" still gives "BR".

Signed-off-by: Taksh <takshkothari09@gmail.com>
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.

1 participant