From 99e76fe1e1d31e330b209e2895717e600ecde776 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Tue, 25 Mar 2014 22:25:38 +0100 Subject: [PATCH] Don't add empty string value to valueless attributes --- src/htmlminifier.js | 6 +++--- src/htmlparser.js | 4 ++-- tests/minifier.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index bd7d928..950b9d1 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -267,7 +267,7 @@ attrValue = cleanAttributeValue(tag, attrName, attrValue, options); - if (!options.removeAttributeQuotes || + if (attrValue !== undefined && !options.removeAttributeQuotes || !canRemoveAttributeQuotes(attrValue)) { attrValue = '"' + attrValue + '"'; } @@ -277,8 +277,8 @@ return ''; } - if (options.collapseBooleanAttributes && - isBooleanAttribute(attrName)) { + if (attrValue === undefined || (options.collapseBooleanAttributes && + isBooleanAttribute(attrName))) { attrFragment = attrName; } else { diff --git a/src/htmlparser.js b/src/htmlparser.js index d11272b..96d75ca 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -216,11 +216,11 @@ var value = arguments[2] ? arguments[2] : arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : - fillAttrs[name] ? name : ''; + fillAttrs[name] ? name : arguments[2]; attrs.push({ name: name, value: value, - escaped: value.replace(/(^|[^\\])"/g, '$1"') //" + escaped: value && value.replace(/(^|[^\\])"/g, '$1"') //" }); }); diff --git a/tests/minifier.js b/tests/minifier.js index 5a42440..bd95345 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -35,7 +35,7 @@ equal(minify(''), ''); equal(minify(''), ''); equal(minify('
'), - '
' + '
' ); // https://github.com/kangax/html-minifier/issues/41 -- 2.34.1