Skip to content

Commit 98a9620

Browse files
committed
🐛 Fix Config#clone to clone internal data struct
I had done this for `#dup`, but somehow missed `#clone`.
1 parent b205add commit 98a9620

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/net/imap/config/attr_accessors.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def freeze
5959

6060
private
6161

62+
def initialize_clone(other)
63+
super
64+
@data = other.data.clone
65+
end
66+
6267
def initialize_dup(other)
6368
super
6469
@data = other.data.dup

test/net/imap/test_config.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,47 @@ class ConfigTest < Test::Unit::TestCase
141141
assert_same Config.global, Config.new(Config.global).parent
142142
end
143143

144+
test "#freeze" do
145+
config = Config.new(open_timeout: 1)
146+
config.freeze
147+
assert_raise FrozenError do
148+
config.open_timeout = 2
149+
end
150+
assert_same 1, config.open_timeout
151+
end
152+
153+
test "#dup" do
154+
original = Config.new(open_timeout: 1)
155+
copy = original.dup
156+
refute_same original, copy
157+
copy.open_timeout = 2
158+
assert_equal 1, original.open_timeout
159+
assert_equal 2, copy.open_timeout
160+
161+
original.freeze
162+
copy = original.dup
163+
refute copy.frozen?
164+
copy.open_timeout = 2
165+
assert_equal 2, copy.open_timeout
166+
end
167+
168+
test "#clone" do
169+
original = Config.new(open_timeout: 1)
170+
copy = original.clone
171+
refute_same original, copy
172+
copy.open_timeout = 2
173+
assert_equal 1, original.open_timeout
174+
assert_equal 2, copy.open_timeout
175+
176+
original.freeze
177+
copy = original.clone
178+
assert copy.frozen?
179+
assert_raise FrozenError do
180+
copy.open_timeout = 2
181+
end
182+
assert_equal 1, copy.open_timeout
183+
end
184+
144185
test "#inherited? and #reset(attr)" do
145186
base = Config.new debug: false, open_timeout: 99, idle_response_timeout: 15
146187
child = base.new debug: true, open_timeout: 15, idle_response_timeout: 10

0 commit comments

Comments
 (0)