diff --git a/lib/ldclient-rb/user_filter.rb b/lib/ldclient-rb/user_filter.rb index 8cbf67ca..b67f6844 100644 --- a/lib/ldclient-rb/user_filter.rb +++ b/lib/ldclient-rb/user_filter.rb @@ -15,8 +15,9 @@ def transform_user_props(user_props) user_private_attrs = Set.new((user_props[:privateAttributeNames] || []).map(&:to_sym)) filtered_user_props, removed = filter_values(user_props, user_private_attrs, ALLOWED_TOP_LEVEL_KEYS, IGNORED_TOP_LEVEL_KEYS) - if user_props.has_key?(:custom) - filtered_user_props[:custom], removed_custom = filter_values(user_props[:custom], user_private_attrs) + custom = user_props[:custom] + if !custom.nil? + filtered_user_props[:custom], removed_custom = filter_values(custom, user_private_attrs) removed.merge(removed_custom) end diff --git a/spec/events_spec.rb b/spec/events_spec.rb index c32eeb29..d7854567 100644 --- a/spec/events_spec.rb +++ b/spec/events_spec.rb @@ -408,6 +408,17 @@ def with_processor_and_sender(config) end end + it "treats nil value for custom the same as an empty hash" do + with_processor_and_sender(default_config) do |ep, sender| + user_with_nil_custom = { key: "userkey", custom: nil } + e = { kind: "identify", key: "userkey", user: user_with_nil_custom } + ep.add_event(e) + + output = flush_and_get_events(ep, sender) + expect(output).to contain_exactly(e) + end + end + it "does a final flush when shutting down" do with_processor_and_sender(default_config) do |ep, sender| e = { kind: "identify", key: user[:key], user: user }