lib/contrast/utils/freeze_util.rb in contrast-agent-3.8.5 vs lib/contrast/utils/freeze_util.rb in contrast-agent-3.9.0

- old
+ new

@@ -1,32 +1,28 @@ # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true -cs__scoped_require 'contrast/core_extensions/object' cs__scoped_require 'contrast/utils/duck_utils' module Contrast module Utils # This utility allows us to act on frozen objects, creating an unfrozen # duplicate in those cases where that is possible. class FreezeUtil class << self # Make every attempt to duplicate the frozen object so that it can - # be tracked. Some things, like Nil, True, and False, respond to dup - # but throw a TypeError. This catches that case and returns the - # original. We luck out as these three cases do not get propagated to + # be tracked. # # @param original [Object] something frozen, usually a String # @return [Object] the original or an unfrozen copy def unfreeze_dup original return original unless original.cs__frozen? - return original unless Contrast::Utils::DuckUtils.quacks_like_duplicable?(original) copy = original.dup - if Contrast::Utils::DuckUtils.quacks_like_tracked_hash?(copy) + if Contrast::Utils::DuckUtils.iterable_hash?(copy) copy.each_key do |key| value = original[key] - copy[key] = Contrast::Utils::DuckUtils.quacks_like_duplicable?(original) ? value.dup : value + copy[key] = value.dup end end copy end end