From 38a93a0665456d0cfc9569946a1f6164835b6aea Mon Sep 17 00:00:00 2001
From: darrinsmart <darrin@djs.to>
Date: Mon, 4 Dec 2023 22:34:24 -0800
Subject: [PATCH] Convert git commit summary to valid UTF8. (#28356)

The summary string ends up in the database, and (at least) MySQL &
PostgreSQL require valid UTF8 strings.

Fixes #28178

Co-authored-by: Darrin Smart <darrin@filmlight.ltd.uk>
---
 modules/git/commit.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/git/commit.go b/modules/git/commit.go
index b09be25ba0..4ff8f6148f 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -43,8 +43,9 @@ func (c *Commit) Message() string {
 }
 
 // Summary returns first line of commit message.
+// The string is forced to be valid UTF8
 func (c *Commit) Summary() string {
-	return strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0]
+	return strings.ToValidUTF8(strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0], "?")
 }
 
 // ParentID returns oid of n-th parent (0-based index).