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:
parent
1655ca235d
commit
20cd023c07
2 changed files with 40 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue