From 7004e431eae7a02d9b5908adfd8aa220ca8c58d4 Mon Sep 17 00:00:00 2001 From: John Beck Date: Thu, 17 Nov 2022 17:58:48 -0600 Subject: [PATCH] dup String in strip_string --- lib/strip_attributes.rb | 2 +- test/strip_attributes_test.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/strip_attributes.rb b/lib/strip_attributes.rb index 2eabafb..c0569f0 100644 --- a/lib/strip_attributes.rb +++ b/lib/strip_attributes.rb @@ -52,7 +52,7 @@ def self.strip_record(record, options = {}) def self.strip_string(value, options = {}) return value unless value.is_a?(String) - return value if value.frozen? + value = value.dup allow_empty = options[:allow_empty] collapse_spaces = options[:collapse_spaces] diff --git a/test/strip_attributes_test.rb b/test/strip_attributes_test.rb index f48d872..7b9c2e5 100644 --- a/test/strip_attributes_test.rb +++ b/test/strip_attributes_test.rb @@ -204,10 +204,12 @@ def test_should_strip_and_allow_empty assert_equal "", record.bang end - def test_should_skip_frozen_values - record = StripAllMockRecord.new(frozen: " ice ".freeze) + def test_should_not_mutate_values + record = StripAllMockRecord.new(foo: " foo ") + old_value = record.foo record.valid? - assert_equal " ice ", record.frozen + assert_equal "foo", record.foo + refute_equal old_value, record.foo end def test_should_collapse_duplicate_spaces