Skip to content

Commit

Permalink
Make sure to dup the default value when setting it
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Jul 24, 2023
1 parent b35cef9 commit a118dbd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/datadog/core/configuration/option.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative '../utils/safe_dup'

module Datadog
module Core
module Configuration
Expand Down Expand Up @@ -137,7 +139,7 @@ def default_value
if definition.default.instance_of?(Proc)
context_eval(&definition.default)
else
definition.experimental_default_proc || definition.default
definition.experimental_default_proc || Core::Utils::SafeDup.frozen_or_dup(definition.default)
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/datadog/core/configuration/option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
let(:setter_value) { double('setter_value') }
let(:context) { double('configuration object') }

before do
allow(Datadog::Core::Utils::SafeDup).to receive(:frozen_or_dup) do |args, _block|
args
end
end

describe '#initialize' do
it { expect(option.definition).to be(definition) }
end
Expand Down
6 changes: 6 additions & 0 deletions spec/datadog/core/configuration/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
end
end

before do
allow(Datadog::Core::Utils::SafeDup).to receive(:frozen_or_dup) do |args, _block|
args
end
end

describe 'class behavior' do
describe '#options' do
subject(:options) { options_class.options }
Expand Down

0 comments on commit a118dbd

Please sign in to comment.