/* global test, ok, equal */
-(function(global){
+(function(global) {
'use strict';
var minify = global.minify || require('../dist/htmlminifier.js').minify,
equal(minify('<input title="bar" id="boo" value="hello world">'), '<input title="bar" id="boo" value="hello world">');
});
- test('space normalization around text', function(){
+ test('space normalization around text', function() {
equal(minify(' <p>blah</p>\n\n\n '), '<p>blah</p>');
// tags from collapseWhitespaceSmart()
- ['a', 'b', 'big', 'button', 'code', 'em', 'font', 'i', 'kbd', 'mark', 'q', 's', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u'].forEach(function(el){
+ ['a', 'b', 'big', 'button', 'code', 'em', 'font', 'i', 'kbd', 'mark', 'q', 's', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u'].forEach(function(el) {
equal(minify('<p>foo <' + el + '>baz</' + el + '> bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '> bar</p>');
equal(minify('<p>foo<' + el + '>baz</' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo<' + el + '>baz</' + el + '>bar</p>');
equal(minify('<p>foo <' + el + '>baz</' + el + '>bar</p>', { collapseWhitespace: true }), '<p>foo <' + el + '>baz</' + el + '>bar</p>');
equal(minify(input, { useShortDoctype: false }), input);
});
- test('removing comments', function(){
+ test('removing comments', function() {
input = '<!-- test -->';
equal(minify(input, { removeComments: true }), '');
equal(minify(input, { removeComments: true }), '<style><!-- alert(1) --><\/style>');
});
- test('ignoring comments', function(){
+ test('ignoring comments', function() {
input = '<!--! test -->';
equal(minify(input, { removeComments: true }), input);
equal(minify(input, { removeComments: false }), input);
equal(minify(input, { removeComments: true }), input);
});
- test('conditional comments', function(){
+ test('conditional comments', function() {
input = '<!--[if IE 6]>test<![endif]-->';
equal(minify(input, { removeComments: true }), input);
equal(minify(input, { removeComments: true }), input);
});
- test('collapsing space in conditional comments', function(){
+ test('collapsing space in conditional comments', function() {
input = '<!--[if IE 7]>\n\n \t\n \t\t ' +
'<link rel="stylesheet" href="/css/ie7-fixes.css" type="text/css" />\n\t' +
'<![endif]-->';
equal(minify(input, { removeComments: true }), output);
});
- test('remove comments from scripts', function(){
+ test('remove comments from scripts', function() {
input = '<script><!--alert(1)--><\/script>';
output = '<script><\/script>';
equal(minify(input, { removeCommentsFromCDATA: true }), output);
equal(minify(input, { removeCommentsFromCDATA: true }), output);
});
- test('remove comments from styles', function(){
+ test('remove comments from styles', function() {
input = '<style type="text/css"><!-- p { color: red } --><\/style>';
output = '<style type="text/css">p { color: red }<\/style>';
equal(minify(input, { removeCommentsFromCDATA: true }), output);
equal(minify(input, { removeCommentsFromCDATA: true }), input);
});
- test('remove CDATA sections from scripts/styles', function(){
+ test('remove CDATA sections from scripts/styles', function() {
input = '<script>/*<![CDATA[*/alert(1)/*]]>*/<\/script>';
output = '<script>alert(1)<\/script>';
equal(minify(input, { removeCDATASectionsFromCDATA: true }), output);
});
- test('empty attributes', function(){
+ test('empty attributes', function() {
input = '<p id="" class="" STYLE=" " title="\n" lang="" dir="">x</p>';
equal(minify(input, { removeEmptyAttributes: true }), '<p>x</p>');
equal(minify(input, { removeEmptyAttributes: true }), '<img src="" alt="">');
});
- test('cleaning class/style attributes', function(){
+ test('cleaning class/style attributes', function() {
input = '<p class=" foo bar ">foo bar baz</p>', output;
equal(minify(input, { cleanAttributes: true }), '<p class="foo bar">foo bar baz</p>');
equal(minify(input, { cleanAttributes: true }), output);
});
- test('cleaning URI-based attributes', function(){
+ test('cleaning URI-based attributes', function() {
input = '<a href=" http://example.com ">x</a>';
output = '<a href="http://example.com">x</a>';
equal(minify(input, { cleanAttributes: true }), output);
equal(minify(input, { cleanAttributes: true }), output);
});
- test('removing redundant attributes (<form method="get" ...>)', function(){
+ test('removing redundant attributes (<form method="get" ...>)', function() {
input = '<form method="get">hello world</form>';
equal(minify(input, { removeRedundantAttributes: true }), '<form>hello world</form>');
equal(minify(input, { removeRedundantAttributes: true }), '<form method="post">hello world</form>');
});
- test('removing redundant attributes (<input type="text" ...>)', function(){
+ test('removing redundant attributes (<input type="text" ...>)', function() {
input = '<input type="text">';
equal(minify(input, { removeRedundantAttributes: true }), '<input>');
equal(minify(input, { removeRedundantAttributes: true }), '<input type="checkbox">');
});
- test('removing redundant attributes (<a name="..." id="..." ...>)', function(){
+ test('removing redundant attributes (<a name="..." id="..." ...>)', function() {
input = '<a id="foo" name="foo">blah</a>';
equal(minify(input, { removeRedundantAttributes: true }), '<a id="foo">blah</a>');
equal(minify(input, { removeRedundantAttributes: true }), '<a href="..." id="bar">blah</a>');
});
- test('removing redundant attributes (<script src="..." charset="...">)', function(){
+ test('removing redundant attributes (<script src="..." charset="...">)', function() {
input = '<script type="text/javascript" charset="UTF-8">alert(222);<\/script>';
output = '<script type="text/javascript">alert(222);<\/script>';
equal(minify(input, { removeRedundantAttributes: true }), output);
equal(minify(input, { removeRedundantAttributes: true }), output);
});
- test('removing redundant attributes (<... language="javascript" ...>)', function(){
+ test('removing redundant attributes (<... language="javascript" ...>)', function() {
input = '<script language="Javascript">x=2,y=4<\/script>';
equal(minify(input, { removeRedundantAttributes: true }), '<script>x=2,y=4<\/script>');
equal(minify(input, { removeRedundantAttributes: true }), '<script>x=2,y=4<\/script>');
});
- test('removing redundant attributes (<area shape="rect" ...>)', function(){
+ test('removing redundant attributes (<area shape="rect" ...>)', function() {
input = '<area shape="rect" coords="696,25,958,47" href="#" title="foo">';
output = '<area coords="696,25,958,47" href="#" title="foo">';
equal(minify(input, { removeRedundantAttributes: true }), output);
});
- test('removing redundant attributes (<... = "javascript: ..." ...>)', function(){
+ test('removing redundant attributes (<... = "javascript: ..." ...>)', function() {
input = '<p onclick="javascript:alert(1)">x</p>';
equal(minify(input, { cleanAttributes: true }), '<p onclick="alert(1)">x</p>');
input = '<p onclick=" JavaScript: x">x</p>';
equal(minify(input, { cleanAttributes: true }), '<p onclick="x">x</p>');
- input = '<p title="javascript:(function(){ /* some stuff here */ })()">x</p>';
+ input = '<p title="javascript:(function() { /* some stuff here */ })()">x</p>';
equal(minify(input, { cleanAttributes: true }), input);
});
- test('removing type="text/javascript" attributes', function(){
+ test('removing type="text/javascript" attributes', function() {
input = '<script type="text/javascript">alert(1)<\/script>';
output = '<script>alert(1)<\/script>';
equal(minify(input, { removeScriptTypeAttributes: true }), output);
});
- test('removing type="text/css" attributes', function(){
+ test('removing type="text/css" attributes', function() {
input = '<style type="text/css">.foo { color: red }<\/style>';
output = '<style>.foo { color: red }<\/style>';
equal(minify(input, { removeStyleLinkTypeAttributes: true }), input);
});
- test('removing attribute quotes', function(){
+ test('removing attribute quotes', function() {
input = '<p title="blah" class="a23B-foo.bar_baz:qux" id="moo">foo</p>';
equal(minify(input, { removeAttributeQuotes: true }), '<p title=blah class=a23B-foo.bar_baz:qux id=moo>foo</p>');
equal(minify(input, { removeEmptyElements: true }), output);
});
- test('collapsing boolean attributes', function(){
+ test('collapsing boolean attributes', function() {
input = '<input disabled="disabled">';
equal(minify(input, { collapseBooleanAttributes: true }), '<input disabled>');
equal(minify(input, { collapseBooleanAttributes: true }), '<input multiple>');
});
- test('keeping trailing slashes in tags', function(){
+ test('keeping trailing slashes in tags', function() {
equal(minify('<img src="test"/>', { keepClosingSlash: true }), '<img src="test"/>');
});
- test('removing optional tags', function(){
+ test('removing optional tags', function() {
input = '<html><head><title>hello</title></head><body><p>foo<span>bar</span></p></body></html>';
output = '<html><head><title>hello</title><body><p>foo<span>bar</span></p>';
equal(minify(input, { removeOptionalTags: true }), output);
equal(minify(input), input);
});
- test('removing optional tags in tables', function(){
+ test('removing optional tags in tables', function() {
input = '<table>' +
'<thead><tr><th>foo</th><th>bar</th></tr></thead>' +
equal(minify(input), input);
});
- test('removing optional tags in options', function(){
+ test('removing optional tags in options', function() {
input = '<select><option>foo</option><option>bar</option></select>';
output = '<select><option>foo<option>bar</select>';
equal(minify(input, { removeOptionalTags: true }), output);
equal(minify(input, { removeOptionalTags: true }), output);
});
- test('custom components', function(){
+ test('custom components', function() {
input = '<custom-component>Oh, my.</custom-component>';
output = '<custom-component>Oh, my.</custom-component>';
equal(minify(input), output);
});
- test('HTML4: anchor with block elements', function(){
+ test('HTML4: anchor with block elements', function() {
input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
output = '<a href="#"></a><div>Well, look at me! I\'m a div!</div>';
equal(minify(input, { html5: false }), output);
});
- test('HTML5: anchor with block elements', function(){
+ test('HTML5: anchor with block elements', function() {
input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
output = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
equal(minify(input, { html5: true }), output);
});
- test('HTML5: enabled by default', function(){
+ test('HTML5: enabled by default', function() {
input = '<a href="#"><div>Well, look at me! I\'m a div!</div></a>';
equal(minify(input, { html5: true }), minify(input));