mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 23:20:49 +03: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:
parent
2a61910e82
commit
c0d15a2897
2 changed files with 20 additions and 2 deletions
|
@ -47,6 +47,23 @@ func TestTruncate(t *testing.T) {
|
|||
{3, template.HTML(strings.Repeat("<p>P</p>", 20)), nil, template.HTML("<p>P</p><p>P</p><p>P …</p>"), false},
|
||||
{18, template.HTML("<p>test <b>hello</b> test something</p>"), nil, template.HTML("<p>test <b>hello</b> test …</p>"), false},
|
||||
{4, template.HTML("<p>a<b><i>b</b>c d e</p>"), nil, template.HTML("<p>a<b><i>b</b>c …</p>"), false},
|
||||
{
|
||||
42,
|
||||
template.HTML(`With strangely formatted
|
||||
<a
|
||||
href="#"
|
||||
target="_blank"
|
||||
>HTML</a
|
||||
>
|
||||
inside.`),
|
||||
nil,
|
||||
template.HTML(`With strangely formatted
|
||||
<a
|
||||
href="#"
|
||||
target="_blank"
|
||||
>HTML …</a>`),
|
||||
false,
|
||||
},
|
||||
{10, nil, nil, template.HTML(""), true},
|
||||
{nil, nil, nil, template.HTML(""), true},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue