You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/02/18 08:48:17 UTC

(incubator-answer-plugins) branch dev updated: fix(basic-connector): Correct handling of user length validation. fix #64

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git


The following commit(s) were added to refs/heads/dev by this push:
     new 01420af  fix(basic-connector): Correct handling of user length validation. fix #64
01420af is described below

commit 01420af0634102019394f24161e4b91f323d8a5e
Author: LinkinStars <li...@foxmail.com>
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
 }