Skip to content

Commit bb6157b

Browse files
committed
attrValue check undefined/null explicitly in flushToDOM
1 parent 0c021e7 commit bb6157b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/core/component.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ Component.prototype = {
240240
*/
241241
flushToDOM: function (isDefault) {
242242
var attrValue = isDefault ? this.data : this.attrValue;
243-
// don't ignore boolean values
244-
if (!attrValue && typeof attrValue !== 'boolean') { return; }
243+
if (attrValue === null || attrValue === undefined) { return; }
245244
window.HTMLElement.prototype.setAttribute.call(this.el, this.attrName,
246245
this.stringify(attrValue));
247246
},

tests/core/component.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,16 @@ suite('Component', function () {
979979
sinon.assert.notCalled(updateStub);
980980
assert.equal(HTMLElement.prototype.getAttribute.call(el, 'dummy'), 'color: blue');
981981
});
982+
983+
test('flushes false boolean', function () {
984+
var el = document.createElement('a-entity');
985+
registerComponent('dummy', {
986+
schema: {isDurrr: {default: true}}
987+
});
988+
el.setAttribute('dummy', {isDurrr: false});
989+
el.components.dummy.flushToDOM();
990+
assert.equal(HTMLElement.prototype.getAttribute.call(el, 'dummy'), 'isDurrr: false');
991+
});
982992
});
983993

984994
suite('play', function () {

0 commit comments

Comments
 (0)