Skip to content

Commit 3bf6396

Browse files
committed
fix utf8 handling
1 parent e5066a4 commit 3bf6396

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

services/pull/pull.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"regexp"
1414
"strings"
1515
"time"
16+
"unicode/utf8"
1617

1718
"code.gitea.io/gitea/models/db"
1819
git_model "code.gitea.io/gitea/models/git"
@@ -861,7 +862,12 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ
861862

862863
_, _ = fmt.Fprintf(&stringBuilder, "* %s\n\n", msg)
863864
if maxMsgSize > 0 && stringBuilder.Len() >= maxMsgSize {
864-
tmp := strings.ToValidUTF8(stringBuilder.String()[:maxMsgSize]+"...", "?")
865+
tmp := stringBuilder.String()
866+
wasValidUtf8 := utf8.ValidString(tmp)
867+
tmp = tmp[:maxMsgSize] + "..."
868+
if wasValidUtf8 {
869+
tmp = strings.ToValidUTF8(tmp, "?")
870+
}
865871
stringBuilder.Reset()
866872
stringBuilder.WriteString(tmp)
867873
break

0 commit comments

Comments
 (0)