Skip to content

Commit a2f2160

Browse files
committed
make info_array validate func more strict:
- only value that have same correct length and all item valid are consisdered valid.
1 parent 09ed024 commit a2f2160

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/lib/coerce.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,16 @@ exports.valObjects = {
255255

256256
var items = opts.items;
257257

258-
// valid when one item is valid (which is subject to debate)
258+
if(v.length !== items.length) return false;
259+
260+
// valid when all items are valid
259261
for(var i = 0; i < items.length; i++) {
260262
var isItemValid = exports.validate(v[i], opts.items[i]);
261263

262-
if(isItemValid) return true;
264+
if(!isItemValid) return false;
263265
}
264266

265-
return false;
267+
return true;
266268
}
267269
}
268270
};

test/jasmine/tests/lib_test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,12 @@ describe('Test lib.js:', function() {
968968
});
969969

970970
it('should work for valType \'info_array\' where', function() {
971-
var shouldPass = [[1, 2], [10], [null, 10], [1, 10, null]],
972-
shouldFail = [{}, [], ['aads', null], 'red', null, undefined, ''];
971+
var shouldPass = [[1, 2], [-20, '20']],
972+
shouldFail = [
973+
{}, [], [10], [null, 10], ['aads', null],
974+
'red', null, undefined, '',
975+
[1, 10, null]
976+
];
973977

974978
assert(shouldPass, shouldFail, {
975979
valType: 'info_array',

0 commit comments

Comments
 (0)