Skip to content

Commit 1e67a56

Browse files
committed
🐛 Fix #responses() freezing internal arrays
Now that `:frozen_dup` is the default behavior for `#responses` when it's called without any arguments, a critical bug has become apparent: it was not freezing the internal responses arrays directly, rather than copies of them. Freezing these arrays will, of course, lead to further issues. Ideally, code should be updated to use one of the other forms of `#responses`, since this form is less efficient and also (intentionally) incompatibile with old code that expects it to return mutable arrays. But this is still a major bug. Fixes #581, reported by @yurikoval.
1 parent 1608a0a commit 1e67a56

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/net/imap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def responses(type = nil)
26912691
warn(RESPONSES_DEPRECATION_MSG, uplevel: 1)
26922692
when :frozen_dup
26932693
synchronize {
2694-
responses = @responses.transform_values(&:freeze)
2694+
responses = @responses.transform_values { _1.dup.freeze }
26952695
responses.default_proc = nil
26962696
responses.default = [].freeze
26972697
return responses.freeze

test/net/imap/test_imap_responses.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,17 @@ def assert_responses_warn
166166
assert_equal [], imap.responses["FAKE"]
167167
end
168168
assert_empty stderr
169-
# opt-in to future behavior
169+
# default behavior since 0.6.0
170170
imap.config.responses_without_block = :frozen_dup
171171
stderr = EnvUtil.verbose_warning do
172172
assert imap.responses.frozen?
173173
assert imap.responses["CAPABILITY"].frozen?
174174
assert_equal(%w[IMAP4REV1 NAMESPACE MOVE IDLE UTF8=ACCEPT],
175175
imap.responses["CAPABILITY"].last)
176+
imap.responses do |r|
177+
refute r.frozen?
178+
refute r.values.any?(&:frozen?)
179+
end
176180
end
177181
assert_empty stderr
178182
end

0 commit comments

Comments
 (0)