Skip to content

Commit

Permalink
HTML: support SSI tags, fixes #353
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Nov 26, 2020
1 parent 1b0d1a7 commit 7773075
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
case html.DoctypeToken:
w.Write(doctypeBytes)
case html.CommentToken:
if o.KeepConditionalComments && len(t.Text) > 6 && (bytes.HasPrefix(t.Text, []byte("[if ")) || bytes.HasSuffix(t.Text, []byte("[endif]")) || bytes.HasSuffix(t.Text, []byte("[endif]--"))) {
if o.KeepConditionalComments && 6 < len(t.Text) && (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("<!--[if ")) && bytes.HasSuffix(t.Data, []byte("<![endif]-->")) { // downlevel-hidden
Expand All @@ -103,6 +103,9 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
} else {
w.Write(t.Data) // downlevel-revealed or short downlevel-hidden
}
} else if 1 < len(t.Text) && t.Text[0] == '#' {
// SSI tags
w.Write(t.Data)
}
case html.SvgToken:
if err := m.MinifyMimetype(svgMimeBytes, w, buffer.NewReader(t.Data), nil); err != nil {
Expand Down
1 change: 1 addition & 0 deletions html/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestHTML(t *testing.T) {
{`html`, `html`},
{`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">`, `<!doctype html>`},
{`<!-- comment -->`, ``},
{`<!--# SSI Tag -->`, `<!--# SSI Tag -->`},
{`<style><!--\ncss\n--></style>`, `<style><!--\ncss\n--></style>`},
{`<style>&</style>`, `<style>&</style>`},
{`<html><head></head><body>x</body></html>`, `x`},
Expand Down

0 comments on commit 7773075

Please sign in to comment.