Skip to content

Commit 0c76236

Browse files
committed
no render false attrs
1 parent 02674c2 commit 0c76236

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/posthtml-render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function postHTMLRender(tree, options) {
7777
function attrs(obj) {
7878
var attr = '';
7979
for (var key in obj) {
80-
attr += ' ' + key + ((obj[key] && typeof obj[key] !== 'boolean')? '="' + obj[key] + '"': '');
80+
obj[key] && (attr += ' ' + key + (typeof obj[key] !== 'boolean'? '="' + obj[key] + '"': ''));
8181
}
8282
return attr;
8383
}

posthtml-render.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ describe('PostHTML-Render test', function() {
6868
.to.eql('<div id="header" style="color:red;" data-id="header"></div>');
6969
});
7070

71-
it('boolean', function() {
71+
it('true', function() {
7272
expect(render({ attrs: { disabled: true } })).to.eql('<div disabled></div>');
7373
});
74+
75+
it('false', function() {
76+
expect(render({ attrs: { disabled: false } })).to.eql('<div></div>');
77+
expect(render({ attrs: { disabled: '' } })).to.eql('<div></div>');
78+
});
7479
});
7580

7681
describe('options', function() {

0 commit comments

Comments
 (0)