From 635423218e65bbc33e723552cb73d3b8d79e5b1a Mon Sep 17 00:00:00 2001 From: rainzm Date: Thu, 28 Oct 2021 17:06:07 +0800 Subject: [PATCH] fix(notify): be compatible with Chinese when generating names --- pkg/notify/models/notification.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/notify/models/notification.go b/pkg/notify/models/notification.go index 49d1990380..2e9ed39fe6 100644 --- a/pkg/notify/models/notification.go +++ b/pkg/notify/models/notification.go @@ -151,10 +151,11 @@ func (nm *SNotificationManager) ValidateCreateData(ctx context.Context, userCred } // hack length := 10 - if len(input.Topic) < 10 { - length = len(input.Topic) + topicRunes := []rune(input.Topic) + if len(topicRunes) < 10 { + length = len(topicRunes) } - name := fmt.Sprintf("%s-%s-%s", input.Topic[:length], input.ContactType, nowStr) + name := fmt.Sprintf("%s-%s-%s", string(topicRunes[:length]), input.ContactType, nowStr) var err error input.Name, err = db.GenerateName(ctx, nm, ownerId, name) if err != nil {