Skip to content

Commit 7ec5316

Browse files
committed
coerce.js boolean and subplotid: Actually do checks on array values.
1 parent ef93f2c commit 7ec5316

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/lib/coerce.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,17 @@ exports.valObjectMeta = {
8888
requiredOpts: [],
8989
otherOpts: ['dflt', 'arrayOk'],
9090
coerceFunction: function(v, propOut, dflt) {
91-
if(v === true || v === false) propOut.set(v);
92-
else propOut.set(dflt);
91+
function isBoolean(value) {
92+
return value === true || value === false;
93+
}
94+
95+
if (opts.arrayOk && isArrayOrTypedArray(v) && v.length > 0 && v.every(isBoolean)) {
96+
propOut.set(v);
97+
} else if(isBoolean(v)) {
98+
propOut.set(v);
99+
} else {
100+
propOut.set(dflt);
101+
}
93102
}
94103
},
95104
number: {
@@ -227,16 +236,17 @@ exports.valObjectMeta = {
227236
requiredOpts: ['dflt'],
228237
otherOpts: ['regex', 'arrayOk'],
229238
coerceFunction: function(v, propOut, dflt, opts) {
230-
if(opts.arrayOk && isArrayOrTypedArray(v)) {
231-
propOut.set(v);
232-
return;
233-
}
234239
var regex = opts.regex || counterRegex(dflt);
235-
if(typeof v === 'string' && regex.test(v)) {
240+
function isSubplotId(value) {
241+
return typeof value === 'string' && regex.test(value);
242+
}
243+
if (opts.arrayOk && isArrayOrTypedArray(v) && v.length > 0 && v.every(isSubplotId)) {
236244
propOut.set(v);
237-
return;
245+
} else if(isSubplotId(v)) {
246+
propOut.set(v);
247+
} else {
248+
propOut.set(dflt);
238249
}
239-
propOut.set(dflt);
240250
},
241251
validateFunction: function(v, opts) {
242252
var dflt = opts.dflt;

0 commit comments

Comments
 (0)