fix: allow non-Latin characters in display names - #1576
Open
culfin wants to merge 1 commit into
Open
Conversation
Registering with a display name such as "Jürgen Müller" fails with
"Erlaubt sind a-z, 0-9, - . _". Two checks reject it, both using \w,
which means [A-Za-z0-9_] in JavaScript as well as in Go:
ui/.../SignUpForm/index.tsx const nameRegex = /^[\w.-\s]{2,30}$/
pkg/checker/username.go usernameReg = `^[\w.\- ]{2,30}$`
This affects every language except English. The second check is not
really about the display name: MakeUsername derives the username from
it, and the username ends up in a profile URL, so it is restricted on
purpose. The restriction is simply applied one step too early.
Answer already solves this elsewhere. Question URLs are transliterated
in pkg/htmltext via unidecode.Unidecode, and MakeUsername already
handles Chinese through pinyin. This change carries that idea through:
- transliterate the display name before deriving the username, using
the dependency the project already ships (go-unidecode)
- drop what transliteration may leave behind — "Ольга" becomes
"Ol'ga", and an apostrophe is not a valid username character
- widen the front-end check to Unicode letters and digits
The display name keeps its original spelling; only the derived username
is transliterated:
Jürgen Müller -> jurgen-muller
José García -> jose-garcia
Ольга -> olga
Ελένη -> elene
Straße -> strasse
Chinese input is unaffected — pinyin still runs first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Registering with a display name such as
Jürgen Müllerfails. The formshows "Erlaubt sind a-z, 0-9, - . _" and the request never succeeds.
Two checks reject it, both relying on
\w, which means[A-Za-z0-9_]inJavaScript as well as in Go:
ui/src/pages/Users/Register/components/SignUpForm/index.tsx:60const nameRegex = /^[\w.-\s]{2,30}$/pkg/checker/username.go:25usernameReg = `^[\w.\- ]{2,30}$`This affects every language except English — German umlauts, accented
letters in French, Spanish or Portuguese, Cyrillic, Greek. Answer ships
translations for over 40 languages, but a user whose name contains a
letter outside ASCII cannot register under it.
Why the check exists
The second check is not really about the display name.
MakeUsernamederives the username from it, and the username appears in a profile URL,
so restricting it makes sense. The restriction is just applied one step
too early — to the display name rather than to the derived username.
Approach
Answer already solves exactly this problem elsewhere: question URLs are
transliterated in
pkg/htmltextviaunidecode.Unidecode, andMakeUsernamealready handles Chinese throughpinyin. This changecarries that idea through.
github.com/mozillazg/go-unidecode— already a direct dependency.ОльгаbecomesOl'ga,and an apostrophe is not a valid username character.
\p{L},\p{N}).The display name keeps its original spelling. Only the derived username
is transliterated:
Chinese input is unaffected —
pinyinstill runs first, and its outputis already ASCII.
Notes
gofmtclean.member accounts to Answer; roughly one in twenty names carries a
character outside ASCII.