diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-07-05 22:18:51 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-07-05 22:18:51 -0700 |
commit | 53deb0b8cd1899ec325eca93631b3e137bdd3ec3 (patch) | |
tree | 23894ed57040ea689e9f60243656e1889d39a275 /vendor/github.com/tdewolff/minify/html/html.go | |
parent | e1c56b2e53ba3c6f48d5e159d18ae59c180cc388 (diff) |
Refactor assets bundler and split Javascript files
Diffstat (limited to 'vendor/github.com/tdewolff/minify/html/html.go')
-rw-r--r-- | vendor/github.com/tdewolff/minify/html/html.go | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/vendor/github.com/tdewolff/minify/html/html.go b/vendor/github.com/tdewolff/minify/html/html.go index e6236f0..626fab2 100644 --- a/vendor/github.com/tdewolff/minify/html/html.go +++ b/vendor/github.com/tdewolff/minify/html/html.go @@ -80,10 +80,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]"))) { + if o.KeepConditionalComments && len(t.Text) > 6 && (bytes.HasPrefix(t.Text, []byte("[if ")) || bytes.Equal(t.Text, []byte("[endif]")) || bytes.Equal(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("<!--[if ")) { // downlevel-hidden + if bytes.HasPrefix(t.Data, []byte("<!--[if ")) && len(t.Data) > len("<!--[if ]><![endif]-->") { // downlevel-hidden begin := bytes.IndexByte(t.Data, '>') + 1 end := len(t.Data) - len("<![endif]-->") if _, err := w.Write(t.Data[:begin]); err != nil { @@ -95,7 +95,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st if _, err := w.Write(t.Data[end:]); err != nil { return err } - } else if _, err := w.Write(t.Data); err != nil { // downlevel-revealed + } else if _, err := w.Write(t.Data); err != nil { // downlevel-revealed or short downlevel-hidden return err } } @@ -281,13 +281,16 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st attrs := tb.Attributes(html.Content, html.Http_Equiv, html.Charset, html.Name) if content := attrs[0]; content != nil { if httpEquiv := attrs[1]; httpEquiv != nil { - content.AttrVal = minify.ContentType(content.AttrVal) - if charset := attrs[2]; charset == nil && parse.EqualFold(httpEquiv.AttrVal, []byte("content-type")) && bytes.Equal(content.AttrVal, []byte("text/html;charset=utf-8")) { - httpEquiv.Text = nil - content.Text = []byte("charset") - content.Hash = html.Charset - content.AttrVal = []byte("utf-8") + if charset := attrs[2]; charset == nil && parse.EqualFold(httpEquiv.AttrVal, []byte("content-type")) { + content.AttrVal = minify.Mediatype(content.AttrVal) + if bytes.Equal(content.AttrVal, []byte("text/html;charset=utf-8")) { + httpEquiv.Text = nil + content.Text = []byte("charset") + content.Hash = html.Charset + content.AttrVal = []byte("utf-8") + } } else if parse.EqualFold(httpEquiv.AttrVal, []byte("content-style-type")) { + content.AttrVal = minify.Mediatype(content.AttrVal) defaultStyleType, defaultStyleParams = parse.Mediatype(content.AttrVal) if defaultStyleParams != nil { defaultInlineStyleParams = defaultStyleParams @@ -296,6 +299,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st defaultInlineStyleParams = map[string]string{"inline": "1"} } } else if parse.EqualFold(httpEquiv.AttrVal, []byte("content-script-type")) { + content.AttrVal = minify.Mediatype(content.AttrVal) defaultScriptType, defaultScriptParams = parse.Mediatype(content.AttrVal) } } @@ -365,7 +369,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st if attr.Traits&caselessAttr != 0 { val = parse.ToLower(val) if attr.Hash == html.Enctype || attr.Hash == html.Codetype || attr.Hash == html.Accept || attr.Hash == html.Type && (t.Hash == html.A || t.Hash == html.Link || t.Hash == html.Object || t.Hash == html.Param || t.Hash == html.Script || t.Hash == html.Style || t.Hash == html.Source) { - val = minify.ContentType(val) + val = minify.Mediatype(val) } } if rawTagHash != 0 && attr.Hash == html.Type { |