Skip to content

Commit bfa30db

Browse files
committed
handle falsey values correctly in coerce2
1 parent 391f602 commit bfa30db

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/lib/coerce.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,10 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
315315
*/
316316
exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) {
317317
var propIn = nestedProperty(containerIn, attribute),
318-
propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt);
318+
propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt),
319+
valIn = propIn.get();
319320

320-
return propIn.get() ? propOut : false;
321+
return (valIn !== undefined && valIn !== null) ? propOut : false;
321322
};
322323

323324
/*

test/jasmine/tests/lib_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ describe('Test lib.js:', function() {
674674

675675
it('should set a value and return the value it sets when user input is valid', function() {
676676
var colVal = 'red',
677-
sizeVal = 14,
677+
sizeVal = 0, // 0 is valid but falsey
678678
attrs = {testMarker: {testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
679679
testSize: {valType: 'number', dflt: 20}}},
680680
obj = {testMarker: {testColor: colVal, testSize: sizeVal}},
@@ -706,7 +706,7 @@ describe('Test lib.js:', function() {
706706

707707
it('should return false if there is no user input', function() {
708708
var colVal = null,
709-
sizeVal = null,
709+
sizeVal, // undefined
710710
attrs = {testMarker: {testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
711711
testSize: {valType: 'number', dflt: 20}}},
712712
obj = {testMarker: {testColor: colVal, testSize: sizeVal}},

0 commit comments

Comments
 (0)