mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
strings: fix Truncate behavior for formatted html
Before this fix, strings.Truncate would erroneously re-include attributes from the opening tag in the closing tag when closing formatted html, due to a bug in how tagnames were extracted from the regex capture group for html tags used in `truncate.go`. This change ensures that only the tagname is retained and all attributes are discarded when storing the tags for closing them later. Fixes #10399
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
2a61910e82
commit
c0d15a2897
@@ -18,6 +18,7 @@ import (
|
||||
"html"
|
||||
"html/template"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -92,12 +93,12 @@ func (ns *Namespace) Truncate(s any, options ...any) (template.HTML, error) {
|
||||
}
|
||||
|
||||
if isHTML {
|
||||
// Make sure we keep tag of HTML tags
|
||||
// Make sure we keep tagname of HTML tags
|
||||
slice := text[i:]
|
||||
m := tagRE.FindStringSubmatchIndex(slice)
|
||||
if len(m) > 0 && m[0] == 0 {
|
||||
nextTag = i + m[1]
|
||||
tagname := slice[m[4]:m[5]]
|
||||
tagname := strings.Fields(slice[m[4]:m[5]])[0]
|
||||
lastWordIndex = lastNonSpace
|
||||
_, singlet := htmlSinglets[tagname]
|
||||
if !singlet && m[6] == -1 {
|
||||
|
Reference in New Issue
Block a user