[#6778] updated the excerpt modifier to properly account for multibyte characters

This commit is contained in:
Gani Georgiev
2025-04-28 12:47:13 +03:00
parent 9bee3bd0fd
commit 5713cf422b
3 changed files with 27 additions and 4 deletions

View File

@@ -135,10 +135,14 @@ func (m *excerptModifier) Modify(value any) (any, error) {
result := strings.TrimSpace(builder.String())
if len(result) > m.max {
result = strings.TrimSpace(result[:m.max])
if m.withEllipsis {
result += "..."
// note: casted to []rune to properly account for multi-byte chars
runes := []rune(result)
if len(runes) > m.max {
result = string(runes[:m.max])
result = strings.TrimSpace(result)
if m.withEllipsis {
result += "..."
}
}
}