From 38a701438e269661338235191ab91e4e2377c2ce Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Thu, 24 Nov 2016 13:45:51 +0800 Subject: [PATCH] retain attribute quotes around values containing custom fragments fixes #757 --- src/htmlminifier.js | 8 ++++---- tests/minifier.js | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 61ade0b..f9841bc 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -548,7 +548,7 @@ function normalizeAttr(attr, attrs, tag, options) { }; } -function buildAttr(normalized, hasUnarySlash, options, isLast) { +function buildAttr(normalized, hasUnarySlash, options, isLast, uidAttr) { var attrName = normalized.name, attrValue = normalized.value, attr = normalized.attr, @@ -556,8 +556,8 @@ function buildAttr(normalized, hasUnarySlash, options, isLast) { attrFragment, emittedAttrValue; - if (typeof attrValue !== 'undefined' && !options.removeAttributeQuotes || - !canRemoveAttributeQuotes(attrValue)) { + if (typeof attrValue !== 'undefined' && (!options.removeAttributeQuotes || + ~attrValue.indexOf(uidAttr) || !canRemoveAttributeQuotes(attrValue))) { if (!options.preventAttributesEscaping) { if (typeof options.quoteCharacter === 'undefined') { var apos = (attrValue.match(/'/g) || []).length; @@ -1030,7 +1030,7 @@ function minify(value, options, partialMarkup) { for (var i = attrs.length, isLast = true; --i >= 0;) { var normalized = normalizeAttr(attrs[i], attrs, tag, options); if (normalized) { - parts.unshift(buildAttr(normalized, hasUnarySlash, options, isLast)); + parts.unshift(buildAttr(normalized, hasUnarySlash, options, isLast, uidAttr)); isLast = false; } } diff --git a/tests/minifier.js b/tests/minifier.js index 3c0d41a..77c63be 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -1829,6 +1829,10 @@ QUnit.test('Ignore custom fragments', function(assert) { assert.equal(minify(input, { collapseWhitespace: true }), output); + + input = ''; + assert.equal(minify(input), input); + assert.equal(minify(input, { removeAttributeQuotes: true }), input); }); QUnit.test('bootstrap\'s span > button > span', function(assert) { -- 2.34.1