Permalink
Browse files

retain attribute quotes around values containing custom fragments

fixes #757
  • Loading branch information...
1 parent 1f689ae commit 38a701438e269661338235191ab91e4e2377c2ce @alexlamsl alexlamsl committed Nov 24, 2016
Showing with 8 additions and 4 deletions.
  1. +4 −4 src/htmlminifier.js
  2. +4 −0 tests/minifier.js
View
@@ -548,16 +548,16 @@ 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,
attrQuote = attr.quote,
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;
}
}
View
@@ -1829,6 +1829,10 @@ QUnit.test('Ignore custom fragments', function(assert) {
assert.equal(minify(input, {
collapseWhitespace: true
}), output);
+
+ input = '<link href="<?php echo \'http://foo/\' ?>">';
+ assert.equal(minify(input), input);
+ assert.equal(minify(input, { removeAttributeQuotes: true }), input);
});
QUnit.test('bootstrap\'s span > button > span', function(assert) {

0 comments on commit 38a7014

Please sign in to comment.