Skip to content

Commit

Permalink
Use object_id to compare by identity
Browse files Browse the repository at this point in the history
The `include?` method compares by hash, meaning `[[]].include?([])`
is `true` despite the two arrays that are being compared not being
the same array instance. Use `object_id` to compare by identity
instead.
  • Loading branch information
unflxw committed Jul 3, 2023
1 parent 4be639f commit 9e8f24a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/appsignal/utils/hash_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,28 @@ def sanitize_value(value, filter_keys, seen)
end

def sanitize_hash(source, filter_keys, seen)
seen << source
seen << source.object_id
{}.tap do |hash|
source.each_pair do |key, value|
next if seen.include?(value.object_id)

hash[key] =
if filter_keys.include?(key.to_s)
FILTERED
else
sanitize_value(value, filter_keys, seen)
end unless seen.include?(value)
end
end
end
end

def sanitize_array(source, filter_keys, seen)
seen << source
seen << source.object_id
[].tap do |array|
source.each_with_index do |item, index|
array[index] = sanitize_value(item, filter_keys, seen) unless seen.include?(item)
next if seen.include?(item.object_id)

array[index] = sanitize_value(item, filter_keys, seen)
end
end
end
Expand Down

0 comments on commit 9e8f24a

Please sign in to comment.