From 8de1f098601177c4feff6d190b6b245f58b9626e Mon Sep 17 00:00:00 2001 From: Duncan Beevers Date: Wed, 20 Aug 2014 12:06:23 -0500 Subject: [PATCH] Quote terminal attribute value by unary slash --- src/htmlminifier.js | 9 +++++---- tests/minifier.js | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 6d07307..ff05b04 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -307,11 +307,12 @@ return markup; } - function normalizeAttribute(attr, attrs, tag, options) { + function normalizeAttribute(attr, attrs, tag, unarySlash, index, options) { var attrName = options.caseSensitive ? attr.name : attr.name.toLowerCase(), attrValue = attr.escaped, - attrFragment; + attrFragment, + isTerminalOfUnarySlash = unarySlash && index === attrs.length - 1; if ((options.removeRedundantAttributes && isAttributeRedundant(tag, attrName, attrValue, attrs)) @@ -327,7 +328,7 @@ attrValue = cleanAttributeValue(tag, attrName, attrValue, options, attrs); if (attrValue !== undefined && !options.removeAttributeQuotes || - !canRemoveAttributeQuotes(attrValue)) { + !canRemoveAttributeQuotes(attrValue) || isTerminalOfUnarySlash) { attrValue = '"' + attrValue + '"'; } @@ -529,7 +530,7 @@ var token; for ( var i = 0, len = attrs.length; i < len; i++ ) { lint && lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped); - token = normalizeAttribute(attrs[i], attrs, tag, options); + token = normalizeAttribute(attrs[i], attrs, tag, unarySlash, i, options); if ( i === len - 1 ) { token += closeTag; } diff --git a/tests/minifier.js b/tests/minifier.js index 7fba30c..2e9753c 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -697,6 +697,9 @@ test('keeping trailing slashes in tags', function() { equal(minify('', { keepClosingSlash: true }), ''); + // https://github.com/kangax/html-minifier/issues/233 + equal(minify('', { keepClosingSlash: true, removeAttributeQuotes: true }), ''); + equal(minify('', { keepClosingSlash: true, removeAttributeQuotes: true }), ''); }); test('removing optional tags', function() { -- 2.34.1