Skip to content

Commit

Permalink
HTML: don't skip text with templates in select tag, fixes #698
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 13, 2024
1 parent 10917c4 commit 943348f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st

// skip text in select and optgroup tags
if t.Hash == Select || t.Hash == Optgroup {
if next := tb.Peek(0); next.TokenType == html.TextToken {
if next := tb.Peek(0); next.TokenType == html.TextToken && !next.HasTemplate {
tb.Shift()
}
}
Expand Down
1 change: 1 addition & 0 deletions html/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func TestHTMLTemplates(t *testing.T) {
{`<div style=" color: {{.Color}} ">`, `<div style=" color: {{.Color}} ">`},
{`<script>alert( {{.Alert}} )</script>`, `<script>alert( {{.Alert}} )</script>`},
{`<button onclick=" alert( {{.Alert}} ) ">`, `<button onclick=" alert( {{.Alert}} ) ">`},
{`<select>{{ range . }}<option>{{ . }}{{ end }}</select>`, `<select>{{ range . }}<option>{{ . }}{{ end }}</select>`},
}

m := minify.New()
Expand Down

0 comments on commit 943348f

Please sign in to comment.