Skip to content

Commit

Permalink
[fix] keep attribute values that are inversed, fixes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Swaagie committed Apr 25, 2015
1 parent 2ad67cc commit 5a1e2f4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ Helpers.prototype.attributes = function attributes(element) {
// should remain unset if retained with `empty` option.
//
result = result + ' ' + key;
if (!self.config.spare && allowed && (bool || !value.length)) return result;
if (!self.config.spare) {
if (!value.length) return result;
if (allowed && (bool && (value === key || 'true' === value))) return result;
}

//
// Return full attribute with value.
Expand Down
4 changes: 3 additions & 1 deletion test/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ describe('Helpers', function () {
html.block.attribs = { disabled: 'disabled' };
expect(helpers.attributes(html.block)).to.be.equal(' disabled=disabled');
html.block.attribs = { autofocus: '' };
expect(helpers.attributes(html.block)).to.be.equal(' autofocus=""');
expect(helpers.attributes(html.block)).to.be.equal(' autofocus');
html.block.attribs = { loop: 'random' };
expect(helpers.attributes(html.block)).to.not.equal(' loop');
expect(helpers.attributes(html.block)).to.be.equal(' loop=random');
html.block.attribs = { class: 'true' };
expect(helpers.attributes(html.block)).to.be.equal(' class=true');
html.block.attribs = { hidden: 'true' };
expect(helpers.attributes(html.block)).to.be.equal(' hidden');
html.block.attribs = { autocomplete: 'off' };
expect(helpers.attributes(html.block)).to.be.equal(' autocomplete=off');
expect(quote.callCount).to.be.equal(5);
});

Expand Down
7 changes: 7 additions & 0 deletions test/minimize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ describe('Minimize', function () {
});
});

it('should retain values on sparse attributes', function (done) {
minimize.parse('<input autocomplete="off">', function (error, result) {
expect(result).to.equal('<input autocomplete=off>');
done();
});
});

it('should remove CDATA from scripts', function (done) {
minimize.parse(html.cdata, function (error, result) {
expect(result).to.equal("<script type=text/javascript>\n\n...code...\n\n</script>");
Expand Down

0 comments on commit 5a1e2f4

Please sign in to comment.