1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

Use runes instead of bytes to truncate JSON feed titles

This fix avoid breaking Unicode string. 

It solves this error:

pq: invalid byte sequence for encoding "UTF8": 0xf0 0x9f 0x9a 0x2e
This commit is contained in:
Jan-Lukas Else 2021-05-31 20:42:59 +02:00 committed by GitHub
parent 1655ca235d
commit 20cd023c07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 2 deletions

View file

@ -182,8 +182,11 @@ func getAuthor(author jsonAuthor) string {
func truncate(str string) string {
max := 100
str = strings.TrimSpace(str)
if len(str) > max {
return str[:max] + "..."
// Convert to runes to be safe with unicode
runes := []rune(str)
if len(runes) > max {
return string(runes[:max]) + "…"
}
return str