Skip to content

Commit a268d2d

Browse files
committed
Merge pull request rails#6676 from aurelian/master
Don't assign the attributes if the list is empty
2 parents fa4b029 + 79c8c4f commit a268d2d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

activerecord/lib/active_record/attribute_assignment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def attributes=(new_attributes)
6464
# user.name # => "Josh"
6565
# user.is_admin? # => true
6666
def assign_attributes(new_attributes, options = {})
67-
return unless new_attributes
67+
return if new_attributes.blank?
6868

6969
attributes = new_attributes.stringify_keys
7070
multi_parameter_attributes = []

activerecord/test/cases/mass_assignment_security_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ def test_mass_assigning_does_not_choke_on_nil
9898
Firm.new.assign_attributes(nil)
9999
end
100100

101+
def test_mass_assigning_does_not_choke_on_empty_hash
102+
Firm.new.assign_attributes({})
103+
end
104+
101105
def test_assign_attributes_uses_default_role_when_no_role_is_provided
102106
p = LoosePerson.new
103107
p.assign_attributes(attributes_hash)

0 commit comments

Comments
 (0)