plataformatec/devise — pull request #2691 by iamvery (2013-10-17 23:27:40+00:00)
Title: Prevent mutation of original values during case and whitespace sanitizations

**TL;DR** - The "downcase" and "strip" before filters for `authenticatable` mutate the original assigned value. This can cause surprising behavior.

## The problem

Consider this contrived example (where `User` is a devise authenticatable model):

```ruby
email = 'ManOSteel@marvel.com'
User.create!(email: email, password: 'password')
puts(email) # => manosteel@marvel.com
```

It's really surprising that the value of a local variable changes right out from under you. The confusion multiples when it's a value of a hash passed into some method that interacts with the devise model.

## The solution

It was pretty simple. Just use assignment along w/ non-mutating string methods to perform these sanitizations. I thought it was pretty interesting that [here](https://github.com/iamvery/devise/blob/b33f6b3fb8c04063f62830abf9ddf6e97b1cc8fd/test/models/database_authenticatable_test.rb#L13) and [here](https://github.com/iamvery/devise/blob/b33f6b3fb8c04063f62830abf9ddf6e97b1cc8fd/test/models/database_authenticatable_test.rb#L24) the developer actually didn't expect these values to be mutated. Clearly [they do](https://gist.github.com/iamvery/7034071).

I'm getting all :+1: from the specs from here, but crazier things, right?

Also, here are [before](https://gist.github.com/iamvery/7033868) and [after](https://gist.github.com/iamvery/7033880) examples that illustrate the problem as well.

Thank you for a great resource for the Ruby community and all your hard work! Please let me know if I'm way off base or you would like any additional work to the PR in order to have it merged :smile: