From a8ba821b5bd8dce36de6fa5bca9a8e6d39d8e609 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Thu, 13 Sep 2018 15:50:26 +1200 Subject: [PATCH] Keep empty value attr on radio input, fixes #226 --- html/html.go | 15 ++++++++++++--- html/html_test.go | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/html/html.go b/html/html.go index 73a03e1363..2fdc454baa 100644 --- a/html/html.go +++ b/html/html.go @@ -312,7 +312,17 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st if attrs[0] != nil && attrs[1] != nil { attrs[1].Text = nil } - } + } else if t.Hash == html.Input { + attrs := tb.Attributes(html.Type, html.Value) + if t, value := attrs[0], attrs[1]; t != nil && value != nil { + isRadio := parse.EqualFold(t.AttrVal, []byte("radio")) + if !isRadio && len(value.AttrVal) == 0 { + value.Text = nil + } else if isRadio && parse.EqualFold(value.AttrVal, []byte("on")) { + value.Text = nil + } + } + } // write attributes htmlEqualIdName := false @@ -343,8 +353,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st attr.Hash == html.Lang || attr.Hash == html.Name || attr.Hash == html.Title || - attr.Hash == html.Action && t.Hash == html.Form || - attr.Hash == html.Value && t.Hash == html.Input) { + attr.Hash == html.Action && t.Hash == html.Form) { continue // omit empty attribute values } if attr.Traits&caselessAttr != 0 { diff --git a/html/html_test.go b/html/html_test.go index 077edcc0fc..dbd11eee32 100644 --- a/html/html_test.go +++ b/html/html_test.go @@ -51,6 +51,8 @@ func TestHTML(t *testing.T) { {``, ``}, {``, ``}, {`
`, `
`}, + {``, ``}, + {``, ``}, // increase coverage {``, ``},