This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch fix/basic in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git
commit 9e1aef727def457927ca5577177b685878cea909 Author: LinkinStars <[email protected]> AuthorDate: Sun Feb 18 16:48:04 2024 +0800 fix(basic-connector): Correct handling of user length validation. fix #64 --- connector-basic/basic.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/connector-basic/basic.go b/connector-basic/basic.go index c3327b5..63f437e 100644 --- a/connector-basic/basic.go +++ b/connector-basic/basic.go @@ -27,6 +27,7 @@ import ( "regexp" "strings" "time" + "unicode/utf8" "github.com/apache/incubator-answer-plugins/connector-basic/i18n" "github.com/apache/incubator-answer/pkg/checker" @@ -184,12 +185,11 @@ func (g *Connector) formatUserInfo(userInfo plugin.ExternalLoginUserInfo) ( userInfoFormatted.Username = replaceUsernameReg.ReplaceAllString(userInfoFormatted.Username, "_") } - if len(userInfoFormatted.DisplayName) < 4 { - userInfoFormatted.DisplayName = userInfoFormatted.DisplayName + strings.Repeat("_", 4-len(userInfoFormatted.DisplayName)) - } - - if len(userInfoFormatted.DisplayName) > 30 { - userInfoFormatted.DisplayName = userInfoFormatted.DisplayName[:30] + usernameLength := utf8.RuneCountInString(userInfoFormatted.Username) + if usernameLength < 4 { + userInfoFormatted.Username = userInfoFormatted.Username + strings.Repeat("_", 4-usernameLength) + } else if usernameLength > 30 { + userInfoFormatted.Username = string([]rune(userInfoFormatted.Username)[:30]) } return userInfoFormatted }
