@@ -1421,6 +1421,16 @@ describe('DataAccessObject', function() {
14211421 assert . deepEqual ( where , { or : [ { age : 10 } , { vip : true } ] } ) ;
14221422 } ) ;
14231423
1424+ it ( 'continues to coerce properties after a logical operator' , function ( ) {
1425+ var clause = { and : [ { age : '10' } ] , vip : 'true' } ;
1426+
1427+ // Key order is predictable but not guaranteed. We prefer false negatives (failure) to false positives.
1428+ assert ( Object . keys ( clause ) [ 0 ] === 'and' , 'Unexpected key order.' ) ;
1429+
1430+ where = model . _coerce ( clause ) ;
1431+ assert . deepEqual ( where , { and : [ { age : 10 } ] , vip : true } ) ;
1432+ } ) ;
1433+
14241434 it ( 'should throw if the where property is not an object' , function ( ) {
14251435 try {
14261436 // The where clause has to be an object
@@ -1473,6 +1483,20 @@ describe('DataAccessObject', function() {
14731483 assert ( error , 'An error should have been thrown' ) ;
14741484 } ) ;
14751485
1486+ it ( 'throws an error when malformed logical operators follow valid logical clauses' , function ( ) {
1487+ var invalid = { and : [ { x : 1 } ] , or : 'bogus' } ;
1488+
1489+ // Key order is predictable but not guaranteed. We prefer false negatives (failure) to false positives.
1490+ assert ( Object . keys ( invalid ) [ 0 ] !== 'or' , 'Unexpected key order.' ) ;
1491+
1492+ try {
1493+ model . _coerce ( invalid ) ;
1494+ } catch ( err ) {
1495+ error = err ;
1496+ }
1497+ assert ( error , 'An error should have been thrown' ) ;
1498+ } ) ;
1499+
14761500 it ( 'should throw if filter property is not an object' , function ( ) {
14771501 var filter = null ;
14781502 try {
0 commit comments