Skip to content

Commit

Permalink
Merge pull request rails#6676 from aurelian/master
Browse files Browse the repository at this point in the history
Don't assign the attributes if the list is empty
  • Loading branch information
rafaelfranca committed Jun 12, 2012
1 parent 6522a12 commit 32709ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/attribute_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def attributes=(new_attributes)
# user.name # => "Josh"
# user.is_admin? # => true
def assign_attributes(new_attributes, options = {})
return unless new_attributes
return if new_attributes.blank?

attributes = new_attributes.stringify_keys
multi_parameter_attributes = []
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/mass_assignment_security_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def test_mass_assigning_does_not_choke_on_nil
Firm.new.assign_attributes(nil)
end

def test_mass_assigning_does_not_choke_on_empty_hash
Firm.new.assign_attributes({})
end

def test_assign_attributes_uses_default_role_when_no_role_is_provided
p = LoosePerson.new
p.assign_attributes(attributes_hash)
Expand Down

0 comments on commit 32709ea

Please sign in to comment.