diff --git a/lib/strip_attributes.rb b/lib/strip_attributes.rb index 13db4ed..cf72e64 100644 --- a/lib/strip_attributes.rb +++ b/lib/strip_attributes.rb @@ -52,12 +52,14 @@ def self.strip_record(record, options = {}) def self.strip_string(value, options = {}) return value unless value.is_a?(String) + # TODO: FUTURE CHANGE: return value if value.frozen? allow_empty = options[:allow_empty] collapse_spaces = options[:collapse_spaces] replace_newlines = options[:replace_newlines] regex = options[:regex] + value = value.dup value.gsub!(regex, "") if regex if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_SPACE) diff --git a/test/strip_attributes_test.rb b/test/strip_attributes_test.rb index 317870e..f9d661f 100644 --- a/test/strip_attributes_test.rb +++ b/test/strip_attributes_test.rb @@ -13,6 +13,7 @@ def self.included(base) base.attribute :qux base.attribute :strip_me base.attribute :skip_me + base.attribute :frozen end end @@ -203,6 +204,12 @@ def test_should_strip_and_allow_empty assert_equal "", record.bang end + def test_should_strip_frozen_values + record = StripAllMockRecord.new(frozen: " ice ".freeze) + record.valid? + assert_equal "ice", record.frozen + end + def test_should_collapse_duplicate_spaces record = CollapseDuplicateSpaces.new(@init_params) record.valid?