return trimWhitespace(attrValue);
}
else if (attrName === 'style') {
- attrValue = trimWhitespace(attrValue).replace(/\s*;\s*$/, '');
+ attrValue = trimWhitespace(attrValue);
+ if (attrValue) {
+ attrValue = attrValue.replace(/\s*;\s*$/, '');
+ }
if (options.minifyCSS) {
return minifyCSS(attrValue, options.minifyCSS);
}
'?:down|up|over|move|out)|key(?:press|down|up)))$');
function canDeleteEmptyAttribute(tag, attrName, attrValue) {
- var isValueEmpty = /^(["'])?\s*\1$/.test(attrValue);
+ var isValueEmpty = !attrValue || /^(["'])?\s*\1$/.test(attrValue);
if (isValueEmpty) {
return (
(tag === 'input' && attrName === 'value') ||
input = '<img src="" alt="">';
equal(minify(input, { removeEmptyAttributes: true }), '<img src="" alt="">');
+
+ // preserve unrecognized attribute
+ // remove recognized attrs with unspecified values
+ input = '<div data-foo class id style title lang dir onfocus onblur onchange onclick ondblclick onmousedown onmouseup onmouseover onmousemove onmouseout onkeypress onkeydown onkeyup></div>';
+ equal(minify(input, { removeEmptyAttributes: true }), '<div data-foo></div>');
});
test('cleaning class/style attributes', function() {