rmm5t / strip_attributes

:hocho: An ActiveModel extension that automatically strips all attributes of leading and trailing whitespace before validation. If the attribute is blank, it strips the value to nil.
https://github.com/rmm5t/strip_attributes
MIT License
558 stars 51 forks source link

Prevent String mutation #64

Open jrbeck opened 1 year ago

jrbeck commented 1 year ago

We had a bug with frozen Strings. It's not clear that the stripping was also mutating, and it was failing silently on the frozen String. I figure there are basically 2 ways to go here: raise on the frozen String or dup the String.

As I see no reason to expect that this method mutates the String (ie it's not a bang method like the gsub! that actually mutates), the dup method seems appropriate.