Skip to content

🐛 Fix SequenceSet#xor crash when set is frozen #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/net/imap/sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def &(other)
#
# <tt>(seqset ^ other)</tt> is equivalent to <tt>((seqset | other) -
# (seqset & other))</tt>.
def ^(other) remain_frozen (self | other).subtract(self & other) end
def ^(other) remain_frozen (dup | other).subtract(self & other) end
alias xor :^

# :call-seq:
Expand Down
4 changes: 3 additions & 1 deletion test/net/imap/test_sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ def compare_to_reference_set(nums, set, seqset)
data "#union", {transform: ->{ _1 | (1..100) }, }
data "#intersection", {transform: ->{ _1 & (1..100) }, }
data "#difference", {transform: ->{ _1 - (1..100) }, }
# data "#xor", {transform: ->{ _1 ^ (1..100) }, }
data "#xor", {transform: ->{ _1 ^ (1..100) }, }
data "#complement", {transform: ->{ ~_1 }, }
data "#normalize", {transform: ->{ _1.normalize }, }
data "#limit", {transform: ->{ _1.limit(max: 22) }, freeze: :always }
data "#limit => empty", {transform: ->{ _1.limit(max: 1) }, freeze: :always }
test "transforms keep frozen status" do |data|
data => {transform:}
set = SequenceSet.new("2:4,7:11,99,999")
dup = set.dup
result = transform.to_proc.(set)
assert_equal dup, set, "transform should not modified"
if data in {freeze: :always}
assert result.frozen?, "this transform always returns frozen"
else
Expand Down