fix: sanitize invalid UTF-8 in incoming email, fix widget scroll flicker

This commit is contained in:
Abhinav Raut
2026-05-29 21:00:48 +05:30
parent 4bfb90b33b
commit 870f66c229
10 changed files with 80 additions and 16 deletions
+9
View File
@@ -25,6 +25,15 @@ var (
regexpConvUUID = regexp.MustCompile(`(?i)\+conv-[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}@`)
)
// SanitizeUTF8 removes NUL bytes and replaces invalid UTF-8 byte sequences with the Unicode replacement character.
func SanitizeUTF8(s string) string {
if s == "" {
return s
}
s = strings.ReplaceAll(s, "\x00", "")
return strings.ToValidUTF8(s, "")
}
// HTML2Text converts HTML to text.
func HTML2Text(html string) string {
out, err := html2text.FromString(html, html2text.Options{TextOnly: true})