From c08a11ca4ab46b714427f8a8789984a4728ea167 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Sat, 13 Oct 2018 23:47:19 +1300 Subject: [PATCH] Fix panic for conditional comments, fixes #229 --- html/html.go | 4 ++-- html/html_test.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/html/html.go b/html/html.go index 2fdc454baa..8ed61f0d2b 100644 --- a/html/html.go +++ b/html/html.go @@ -75,10 +75,10 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st return err } case html.CommentToken: - if o.KeepConditionalComments && len(t.Text) > 6 && (bytes.HasPrefix(t.Text, []byte("[if ")) || bytes.Equal(t.Text, []byte("[endif]")) || bytes.Equal(t.Text, []byte(" 6 && (bytes.HasPrefix(t.Text, []byte("[if ")) || bytes.HasSuffix(t.Text, []byte("[endif]")) || bytes.HasSuffix(t.Text, []byte("[endif]--"))) { // [if ...] is always 7 or more characters, [endif] is only encountered for downlevel-revealed // see https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx#syntax - if bytes.HasPrefix(t.Data, []byte("") { // downlevel-hidden + if bytes.HasPrefix(t.Data, []byte("")) { // downlevel-hidden begin := bytes.IndexByte(t.Data, '>') + 1 end := len(t.Data) - len("") if _, err := w.Write(t.Data[:begin]); err != nil { diff --git a/html/html_test.go b/html/html_test.go index dbd11eee32..65822b99b9 100644 --- a/html/html_test.go +++ b/html/html_test.go @@ -180,7 +180,9 @@ func TestHTMLKeepConditionalComments(t *testing.T) { }{ {``, ``}, {` `, ``}, + {` `, ``}, {` `, ``}, + {` `, ``}, } m := minify.New()