Skip to content

Commit

Permalink
Fix array self assignment bug introduced by previous fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dmendel committed Jul 15, 2020
1 parent 4c3be0f commit c6fae73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
= BinData Changelog

== Version 2.4.8

* Bug fix array self assignment. Thanks to Spencer McIntyre.

== Version 2.4.7 (2020-03-31)

* Fix choice assignment inside arrays. Reported by Spencer McIntyre.
Expand Down
1 change: 1 addition & 0 deletions lib/bindata/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def clear?
end

def assign(array)
return if self.equal?(array) # prevent self assignment
raise ArgumentError, "can't set a nil value for #{debug_name}" if array.nil?

@element_list = []
Expand Down
5 changes: 5 additions & 0 deletions test/array_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@
lambda { obj["a"] }.must_raise TypeError
lambda { obj[1, "a"] }.must_raise TypeError
end

it "is unaffected by self assignment" do
obj.assign(obj)
obj.snapshot.must_equal [1, 2, 3, 4, 5]
end
end

describe BinData::Array, "with :read_until" do
Expand Down

0 comments on commit c6fae73

Please sign in to comment.