Skip to content

Commit

Permalink
HTML: fix templates inside <select>
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Sep 21, 2024
1 parent 400c636 commit a7467f2
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 @@ -309,7 +309,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 == Option || 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 @@ -378,6 +378,7 @@ func TestHTMLTemplates(t *testing.T) {
{`<button onclick=" alert( {{.Alert}} ) ">`, `<button onclick=" alert( {{.Alert}} ) ">`},
{`<select>{{ range . }}<option>{{ . }}{{ end }}</select>`, `<select>{{ range . }}<option>{{ . }}{{ end }}</select>`},
{`<p>Hello <code>{{""}}</code> there</p>`, `<p>Hello <code>{{""}}</code> there`},
{`<select><option>Default</option>{{range $i, $lang := .Languages}}<option>{{$lang}}</option>{{end}}</select>`, `<select><option>Default{{range $i, $lang := .Languages}}<option>{{$lang}}{{end}}</select>`},
}

m := minify.New()
Expand Down

0 comments on commit a7467f2

Please sign in to comment.