@@ -190,6 +190,17 @@ describe('lib/core/custom_attribute_condition_evaluator', function() {
190190 var result = customAttributeEvaluator . evaluate ( exactNumberCondition , { } ) ;
191191 assert . isNull ( result ) ;
192192 } ) ;
193+
194+ it ( 'should return null if the condition value is not finite' , function ( ) {
195+ var invalidValueCondition = {
196+ match : 'exact' ,
197+ name : 'lasers_count' ,
198+ type : 'custom_attribute' ,
199+ value : Infinity ,
200+ } ;
201+ var result = customAttributeEvaluator . evaluate ( invalidValueCondition , { lasers_count : 9000 } ) ;
202+ assert . isNull ( result ) ;
203+ } ) ;
193204 } ) ;
194205
195206 describe ( 'with a boolean condition value' , function ( ) {
@@ -279,22 +290,43 @@ describe('lib/core/custom_attribute_condition_evaluator', function() {
279290 assert . isFalse ( result ) ;
280291 } ) ;
281292
282- it ( 'should return null if the user-provided value is not a number' , function ( ) {
293+ it ( 'should return null if the user-provided value is not a finite number' , function ( ) {
283294 var result = customAttributeEvaluator . evaluate ( gtCondition , {
284295 meters_travelled : 'a long way' ,
285296 } ) ;
286297 assert . isNull ( result ) ;
287298
288- var result = customAttributeEvaluator . evaluate ( gtCondition , {
299+ result = customAttributeEvaluator . evaluate ( gtCondition , {
289300 meters_travelled : '1000' ,
290301 } ) ;
291302 assert . isNull ( result ) ;
303+
304+ result = customAttributeEvaluator . evaluate ( gtCondition , {
305+ meters_travelled : Infinity ,
306+ } ) ;
307+ assert . isNull ( result ) ;
292308 } ) ;
293309
294310 it ( 'should return null if there is no user-provided value' , function ( ) {
295311 var result = customAttributeEvaluator . evaluate ( gtCondition , { } ) ;
296312 assert . isNull ( result ) ;
297313 } ) ;
314+
315+ it ( 'should return null if the condition value is not a finite number' , function ( ) {
316+ var userAttributes = { meters_travelled : 58.4 } ;
317+ var invalidValueCondition = {
318+ match : 'gt' ,
319+ name : 'meters_travelled' ,
320+ type : 'custom_attribute' ,
321+ value : Infinity ,
322+ } ;
323+ var result = customAttributeEvaluator . evaluate ( invalidValueCondition , userAttributes ) ;
324+ assert . isNull ( result ) ;
325+
326+ invalidValueCondition . value = null ;
327+ result = customAttributeEvaluator . evaluate ( invalidValueCondition , userAttributes ) ;
328+ assert . isNull ( result ) ;
329+ } ) ;
298330 } ) ;
299331
300332 describe ( 'less than match type' , function ( ) {
@@ -319,21 +351,42 @@ describe('lib/core/custom_attribute_condition_evaluator', function() {
319351 assert . isFalse ( result ) ;
320352 } ) ;
321353
322- it ( 'should return null if the user-provided value is not a number' , function ( ) {
354+ it ( 'should return null if the user-provided value is not a finite number' , function ( ) {
323355 var result = customAttributeEvaluator . evaluate ( ltCondition , {
324356 meters_travelled : true ,
325357 } ) ;
326358 assert . isNull ( result ) ;
327359
328- var result = customAttributeEvaluator . evaluate ( ltCondition , {
360+ result = customAttributeEvaluator . evaluate ( ltCondition , {
329361 meters_travelled : '48.2' ,
330362 } ) ;
331363 assert . isNull ( result ) ;
364+
365+ result = customAttributeEvaluator . evaluate ( ltCondition , {
366+ meters_travelled : Infinity ,
367+ } ) ;
368+ assert . isNull ( result ) ;
332369 } ) ;
333370
334371 it ( 'should return null if there is no user-provided value' , function ( ) {
335372 var result = customAttributeEvaluator . evaluate ( ltCondition , { } ) ;
336373 assert . isNull ( result ) ;
337374 } ) ;
375+
376+ it ( 'should return null if the condition value is not a finite number' , function ( ) {
377+ var userAttributes = { meters_travelled : 10 } ;
378+ var invalidValueCondition = {
379+ match : 'lt' ,
380+ name : 'meters_travelled' ,
381+ type : 'custom_attribute' ,
382+ value : Infinity ,
383+ } ;
384+ var result = customAttributeEvaluator . evaluate ( invalidValueCondition , userAttributes ) ;
385+ assert . isNull ( result ) ;
386+
387+ invalidValueCondition . value = { } ;
388+ result = customAttributeEvaluator . evaluate ( invalidValueCondition , userAttributes ) ;
389+ assert . isNull ( result ) ;
390+ } ) ;
338391 } ) ;
339392} ) ;
0 commit comments