Skip to content

Commit e989db0

Browse files
committed
Move to opt-in character replacement
1 parent e947e57 commit e989db0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ And the following unique queues:
598598
- userid - use the userid / sub attribute
599599
- nickname - use the nickname attribute
600600
- email - use the username part of the email attribute
601-
- email-normalized - use the username part of the email attribute with diacritics and single-quotes removed, and any other non-supported username characters replaced with a `-` character
601+
- email-normalized - use the username part of the email attribute with diacritics and single-quotes removed, and `\s,` replaced with `-`
602602
- `UPDATE_AVATAR`: **false**: Update avatar if available from oauth2 provider. Update will be performed on each login.
603603
- `ACCOUNT_LINKING`: **login**: How to handle if an account / email already exists:
604604
- disabled - show an error

models/user/user.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,12 @@ func GetUserSalt() (string, error) {
520520
return hex.EncodeToString(rBytes), nil
521521
}
522522

523-
// Developer warning: The set of characters here can safely expand without a breaking change,
523+
// Note: The set of characters here can safely expand without a breaking change,
524524
// but characters removed from this set can cause user account linking to break
525525
var (
526-
invalidUsernameCharsRE = regexp.MustCompile(`[^\w-.]`)
526+
removeCharsRE = regexp.MustCompile(`['\x60]`)
527527
removeDiacriticsTransform = transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
528-
removeChars = strings.NewReplacer("'", "", "`", "")
528+
replaceCharsRE = regexp.MustCompile(`[\s,]`)
529529
)
530530

531531
// normalizeUserName returns a string with single-quotes and diacritics
@@ -536,7 +536,7 @@ func NormalizeUserName(s string) (string, error) {
536536
if err != nil {
537537
return "", fmt.Errorf("Failed to normalize character `%v` in provided username `%v`", s[n], s)
538538
}
539-
return invalidUsernameCharsRE.ReplaceAllString(removeChars.Replace(strDiacriticsRemoved), "-"), nil
539+
return replaceCharsRE.ReplaceAllLiteralString(removeCharsRE.ReplaceAllLiteralString(strDiacriticsRemoved, ""), "-"), nil
540540
}
541541

542542
var (

0 commit comments

Comments
 (0)