-
Notifications
You must be signed in to change notification settings - Fork 172
Open
Description
Since the CollectionMembershipOperator coerces the type of the item being tested to the first (or first non-null) element in the list, it can lead to unexpected/unintuitive results.
jinjava/src/main/java/com/hubspot/jinjava/el/ext/CollectionMembershipOperator.java
Lines 34 to 47 in af0819a
for (Object value : collection) { | |
if (value == null) { | |
if (o1 == null) { | |
return Boolean.TRUE; | |
} | |
} else { | |
try { | |
return collection.contains(converter.convert(o1, value.getClass())); | |
} catch (ELException e) { | |
return Boolean.FALSE; | |
} | |
} | |
} | |
} |
{{ null in [null, 1, 2] }} {# true #}
{{ null in [1, null, 2] }} {# false - null converted to 0; no 0 in list #}
{{ null in [1, null, 2, 0] }} {# true - because of the 0 in the list, not the null #}
{{ null in [0, 1, 2] }} {# true #}
{{ 1 in ['1', 2 ] }} {# true - 1 converted to '1' #}
{{ 2 in ['1', 2 ] }} {# false - 2 is converted to '2', no '2' in list #}
{{ 1 in [false, 1] }} {# false - 1 converted to true #}
{{ 1 in [true, 0] }} {# true #}
{{ 1 in [null, 'abc', 1] }} {# false #}
{{ '' in [1, '', 2] }} {# false #}
{{ '' in [0, 1, 2] }} {# true #}
(The same applies to is containing
, e.g. [false, 1] is containing 1
is false)
Metadata
Metadata
Assignees
Labels
No labels