@@ -1445,6 +1445,16 @@ describe('DataAccessObject', function() {
14451445 assert . deepEqual ( where , { or : [ { age : 10 } , { vip : true } ] } ) ;
14461446 } ) ;
14471447
1448+ it ( 'continues to coerce properties after a logical operator' , function ( ) {
1449+ var clause = { and : [ { age : '10' } ] , vip : 'true' } ;
1450+
1451+ // Key order is predictable but not guaranteed. We prefer false negatives (failure) to false positives.
1452+ assert ( Object . keys ( clause ) [ 0 ] === 'and' , 'Unexpected key order.' ) ;
1453+
1454+ where = model . _coerce ( clause ) ;
1455+ assert . deepEqual ( where , { and : [ { age : 10 } ] , vip : true } ) ;
1456+ } ) ;
1457+
14481458 it ( 'should throw if the where property is not an object' , function ( ) {
14491459 try {
14501460 // The where clause has to be an object
@@ -1497,6 +1507,20 @@ describe('DataAccessObject', function() {
14971507 assert ( error , 'An error should have been thrown' ) ;
14981508 } ) ;
14991509
1510+ it ( 'throws an error when malformed logical operators follow valid logical clauses' , function ( ) {
1511+ var invalid = { and : [ { x : 1 } ] , or : 'bogus' } ;
1512+
1513+ // Key order is predictable but not guaranteed. We prefer false negatives (failure) to false positives.
1514+ assert ( Object . keys ( invalid ) [ 0 ] !== 'or' , 'Unexpected key order.' ) ;
1515+
1516+ try {
1517+ model . _coerce ( invalid ) ;
1518+ } catch ( err ) {
1519+ error = err ;
1520+ }
1521+ assert ( error , 'An error should have been thrown' ) ;
1522+ } ) ;
1523+
15001524 it ( 'should throw if filter property is not an object' , function ( ) {
15011525 var filter = null ;
15021526 try {
0 commit comments