| 247 | } |
| 248 | |
| 249 | func TestHTMLKeepSpecialComments(t *testing.T) { |
| 250 | htmlTests := []struct { |
| 251 | html string |
| 252 | expected string |
| 253 | }{ |
| 254 | {`<!--[if IE 6]> <b> </b> <![endif]-->`, `<!--[if IE 6]><b></b><![endif]-->`}, |
| 255 | {`<![if IE 6]> <b> </b> <![endif]>`, `<![if IE 6]><b></b><![endif]>`}, |
| 256 | {`<!--[if IE 6]--> <b> </b> <!--[endif]-->`, `<!--[if IE 6]--><b></b><!--[endif]-->`}, |
| 257 | {`<!--[if !mso]><!--> <b> </b> <!--<![endif]-->`, `<!--[if !mso]><!--><b></b><!--<![endif]-->`}, |
| 258 | {`<!--[if gt IE 6]><!--> <b> </b> <![endif]-->`, `<!--[if gt IE 6]><!--><b></b><![endif]-->`}, |
| 259 | {`<!--[if IE]foo<![endif]-->`, `<!--[if IE]foo<![endif]-->`}, // #596 |
| 260 | {`<!--# SSI-->`, `<!--# SSI-->`}, // #657 |
| 261 | {`<!--[if mso]><noscript><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml></noscript><![endif]-->`, `<!--[if mso]><noscript><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml></noscript><![endif]-->`}, // #832 |
| 262 | } |
| 263 | |
| 264 | m := minify.New() |
| 265 | htmlMinifier := &Minifier{KeepSpecialComments: true} |
| 266 | for _, tt := range htmlTests { |
| 267 | t.Run(tt.html, func(t *testing.T) { |
| 268 | r := bytes.NewBufferString(tt.html) |
| 269 | w := &bytes.Buffer{} |
| 270 | err := htmlMinifier.Minify(m, w, r, nil) |
| 271 | test.Minify(t, tt.html, err, w.String(), tt.expected) |
| 272 | }) |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | func TestHTMLKeepWhitespace(t *testing.T) { |
| 277 | htmlTests := []struct { |