lib/flagsmith/engine/segments/evaluator.rb in flagsmith-3.0.1 vs lib/flagsmith/engine/segments/evaluator.rb in flagsmith-3.1.0

- old
+ new

@@ -54,14 +54,26 @@ def traits_match_segment_condition(identity_traits, condition, segment_id, identity_id) if condition.operator == PERCENTAGE_SPLIT return hashed_percentage_for_object_ids([segment_id, identity_id]) <= condition.value.to_f end - trait = identity_traits.find { |t| t.key == condition.property } + trait = identity_traits.find { |t| t.key.to_s == condition.property } - return condition.match_trait_value?(trait.value) if trait + if [IS_SET, IS_NOT_SET].include?(condition.operator) + return handle_trait_existence_conditions(trait, condition.operator) + end + return condition.match_trait_value?(trait.trait_value) if trait + false + end + + private + + def handle_trait_existence_conditions(matching_trait, operator) + return operator == IS_NOT_SET if matching_trait.nil? + + operator == IS_SET end end end end end