From 9d421b14a8a6a1d039def7d4df5242a1dc9d92fb Mon Sep 17 00:00:00 2001 From: kangax Date: Wed, 19 Jun 2013 13:09:48 +0200 Subject: [PATCH] Better support for boolean attributes. Closes #63. Version 0.5.3 --- dist/all.js | 4 ++-- package.json | 2 +- src/htmlminifier.js | 4 ++-- tests/minifier.js | 11 ++++++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dist/all.js b/dist/all.js index 2b4b676..619bf12 100644 --- a/dist/all.js +++ b/dist/all.js @@ -341,7 +341,7 @@ } })(typeof exports === 'undefined' ? this : exports); /*! - * HTMLMinifier v0.5.2 + * HTMLMinifier v0.5.3 * http://kangax.github.com/html-minifier/ * * Copyright (c) 2010-2013 Juriy "kangax" Zaytsev @@ -472,7 +472,7 @@ } function isBooleanAttribute(attrName) { - return (/^(?:checked|disabled|selected|readonly)$/).test(attrName); + return (/^(?:allowfullscreen|async|autofocus|checked|compact|declare|default|defer|disabled|formnovalidate|hidden|inert|ismap|itemscope|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|readonly|required|reversed|seamless|selected|sortable|truespeed|typemustmatch)$/).test(attrName); } function isUriTypeAttribute(attrName, tag) { diff --git a/package.json b/package.json index 1358125..af3081d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "html-minifier", "description": "HTML minifier with lint-like capabilities.", - "version": "0.5.2", + "version": "0.5.3", "keywords": ["html", "minifier", "lint"], "url" : "http://github.com/kangax/html-minifier", "maintainers": [{ diff --git a/src/htmlminifier.js b/src/htmlminifier.js index ce064ca..e7e6405 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1,5 +1,5 @@ /*! - * HTMLMinifier v0.5.2 + * HTMLMinifier v0.5.3 * http://kangax.github.com/html-minifier/ * * Copyright (c) 2010-2013 Juriy "kangax" Zaytsev @@ -130,7 +130,7 @@ } function isBooleanAttribute(attrName) { - return (/^(?:checked|disabled|selected|readonly)$/).test(attrName); + return (/^(?:allowfullscreen|async|autofocus|checked|compact|declare|default|defer|disabled|formnovalidate|hidden|inert|ismap|itemscope|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|readonly|required|reversed|seamless|selected|sortable|truespeed|typemustmatch)$/).test(attrName); } function isUriTypeAttribute(attrName, tag) { diff --git a/tests/minifier.js b/tests/minifier.js index b49b62d..9b3da95 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -86,7 +86,7 @@ equal(minify('

foo<'+el+'> baz bar

', {collapseWhitespace: true}), '

foo<'+el+'>bazbar

'); equal(minify('

foo <'+el+'> baz bar

', {collapseWhitespace: true}), '

foo <'+el+'>bazbar

'); equal(minify('

foo<'+el+'> baz bar

', {collapseWhitespace: true}), '

foo<'+el+'>baz bar

'); - }) + }) equal(minify('

foo bar

', {collapseWhitespace: true}), '

foo bar

'); equal(minify('

foobar

', {collapseWhitespace: true}), '

foobar

'); equal(minify('

foo bar

', {collapseWhitespace: true}), '

foo bar

'); @@ -548,6 +548,15 @@ input = ''; equal(minify(input, { collapseBooleanAttributes: true }), ''); + + input = ''; + equal(minify(input, { collapseBooleanAttributes: true }), ''); + + input = ''; + equal(minify(input, { collapseBooleanAttributes: true }), ''); + + input = ''; + equal(minify(input, { collapseBooleanAttributes: true }), ''); }); test('removing optional tags', function(){ -- 2.34.1