From 5f67b72cdd89bcfad554b916f6506ca9f5277a11 Mon Sep 17 00:00:00 2001 From: Daniel Kilimnik Date: Thu, 8 May 2025 16:59:41 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20replace=20=C3=9F=20with=20ss=20in=20norm?= =?UTF-8?q?alizeUserName=20(#7817)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using an oauth provider for login, we can't always make sure that only supported characters are included in the name. Therefore there exist normalization rules for the username. In German some names contain the `ß` letter which usually gets replaces by `ss`. Therefore I added this to the `customCharsReplacement` list. Without this fix, the user gets an undescriptive internal server error and the log states `CreateUser: name is invalid []: must be valid alpha or numeric or dash(-_) or dot characters`. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7817 Reviewed-by: Gusted Co-authored-by: Daniel Kilimnik Co-committed-by: Daniel Kilimnik --- models/user/user.go | 2 +- models/user/user_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/models/user/user.go b/models/user/user.go index 5a8c1e9d73..7544e24be6 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -562,7 +562,7 @@ func GetUserSalt() string { // Note: The set of characters here can safely expand without a breaking change, // but characters removed from this set can cause user account linking to break var ( - customCharsReplacement = strings.NewReplacer("Æ", "AE") + customCharsReplacement = strings.NewReplacer("Æ", "AE", "ß", "ss") removeCharsRE = regexp.MustCompile(`['´\x60]`) removeDiacriticsTransform = transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC) replaceCharsHyphenRE = regexp.MustCompile(`[\s~+]`) diff --git a/models/user/user_test.go b/models/user/user_test.go index 139d6b8a47..7263f9510c 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -645,6 +645,7 @@ func Test_NormalizeUserFromEmail(t *testing.T) { {"test", "test", true}, {"Sinéad.O'Connor", "Sinead.OConnor", true}, {"Æsir", "AEsir", true}, + {"Flußpferd", "Flusspferd", true}, // \u00e9\u0065\u0301 {"éé", "ee", true}, {"Awareness Hub", "Awareness-Hub", true},