lib/ldclient-rb/evaluation.rb in ldclient-rb-5.5.4 vs lib/ldclient-rb/evaluation.rb in ldclient-rb-5.5.5
- old
+ new
@@ -187,10 +187,14 @@
}
# Used internally to hold an evaluation result and the events that were generated from prerequisites.
EvalResult = Struct.new(:detail, :events)
+ USER_ATTRS_TO_STRINGIFY_FOR_EVALUATION = [ :key, :secondary ]
+ # Currently we are not stringifying the rest of the built-in attributes prior to evaluation, only for events.
+ # This is because it could affect evaluation results for existing users (ch35206).
+
def error_result(errorKind, value = nil)
EvaluationDetail.new(value, nil, { kind: 'ERROR', errorKind: errorKind })
end
# Evaluates a feature flag and returns an EvalResult. The result.value will be nil if the flag returns
@@ -198,11 +202,13 @@
def evaluate(flag, user, store, logger)
if user.nil? || user[:key].nil?
return EvalResult.new(error_result('USER_NOT_SPECIFIED'), [])
end
+ sanitized_user = Util.stringify_attrs(user, USER_ATTRS_TO_STRINGIFY_FOR_EVALUATION)
+
events = []
- detail = eval_internal(flag, user, store, events, logger)
+ detail = eval_internal(flag, sanitized_user, store, events, logger)
return EvalResult.new(detail, events)
end
def eval_internal(flag, user, store, events, logger)
if !flag[:on]