🐛 Keep accented letters in organization avatar initials (#12328)

get-initials used an ASCII-only [a-zA-Z] match, so names like Ábaco
and Órbita skipped the leading accented letter. Match Unicode letters
with \p{L} (CLJS RegExp + u/g flags) so org default avatars match the
expected first letter. Closes #12324.

AI-assisted-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Pablo Alba 2026-10-19 15:56:05 +02:00 committed by GitHub
parent 655300e4d1
commit c7f16d3236
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 3 deletions

View File

@ -1202,12 +1202,20 @@
(str/replace (str s) #"([*_~`\[\]()>#+=\-|{}.!@\\])" (fn [[_ c]] (str "\\" c)))
""))
;; \p{L} (Unicode letter) works in Java regex natively, but in JavaScript it
;; requires the "u" flag which ClojureScript regex literals don't support.
;; Do not use the "g" flag: a shared global RegExp mutates lastIndex and
;; corrupts later get-initials calls (org avatar lists in the team switcher).
(def ^:private letter-re
#?(:clj #"\p{L}"
:cljs (js/RegExp. "\\p{L}" "u")))
(defn get-initials
"Returns up to two uppercase initials extracted from a string.
Non-letter prefixes in each token are ignored."
Non-letter prefixes in each token are ignored (Unicode letters)."
[name]
(->> (str/split (str/trim (or name "")) #"\s+")
(keep #(first (re-seq #"[a-zA-Z]" %)))
(keep #(re-find letter-re %))
(take 2)
(map str/upper)
(apply str)))

View File

@ -34,7 +34,18 @@
(t/is (= "AB" (d/get-initials "123 Alpha ## beta")))
(t/is (= "PD" (d/get-initials " penpot design tool ")))
(t/is (= "" (d/get-initials nil)))
(t/is (= "" (d/get-initials "!!! ???"))))
(t/is (= "" (d/get-initials "!!! ???")))
;; Accented / Unicode letters (org default avatars)
(t/is (= "Á" (d/get-initials "Ábaco")))
(t/is (= "Ó" (d/get-initials "Órbita")))
(t/is (= "ÁN" (d/get-initials "Álvaro Núñez")))
;; Sequential calls must stay stable (CLJS global RegExp lastIndex)
(t/is (= ["Á" "BB" "JG" "L" "Á"]
(mapv d/get-initials ["Ábaco"
"Black Bird"
"Jean Grey Academy"
"Library"
"Ábaco"]))))
(t/deftest normalize-string-test
;; nil input returns empty string