1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Fix invalid output when truncating Unicode text in templates

This commit is contained in:
Savely Krasovsky 2018-09-21 05:11:13 +03:00 committed by Frédéric Guillot
parent 2538eea177
commit d79bab2997
2 changed files with 54 additions and 9 deletions

View file

@ -5,7 +5,6 @@
package template // import "miniflux.app/template"
import (
"bytes"
"html/template"
"net/mail"
"strings"
@ -80,15 +79,13 @@ func (f *funcMap) Map() template.FuncMap {
},
"dict": dict,
"truncate": func(str string, max int) string {
if len(str) > max {
var buffer bytes.Buffer
buffer.WriteString(str[:max-1])
buffer.WriteString("…")
return buffer.String()
runes := 0
for i := range str {
runes++
if runes > max {
return str[:i] + "…"
}
}
return str
},
"theme_color": func(theme string) string {