Skip to content

Commit

Permalink
Call .dup on string before modifying it in-place.
Browse files Browse the repository at this point in the history
Prevents Ruby 3.4 frozen string warnings.

Fixes rmm5t#76.
  • Loading branch information
gstokkink committed Jan 16, 2025
1 parent 07ad134 commit 33c28f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/strip_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ 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]
replace_newlines = options[:replace_newlines]
Expand Down
5 changes: 4 additions & 1 deletion test/strip_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ def test_should_strip_unicode
skip "multi-byte characters not supported by this version of Ruby" unless StripAttributes::MULTIBYTE_SUPPORTED

assert_equal "foo", StripAttributes.strip("\u200A\u200B foo\u200A\u200B ")
assert_equal "foo\u20AC".force_encoding("ASCII-8BIT"), StripAttributes.strip("foo\u20AC ".force_encoding("ASCII-8BIT"))

str = "foo\u20AC".dup

assert_equal str.force_encoding("ASCII-8BIT"), StripAttributes.strip(str.force_encoding("ASCII-8BIT"))
end
end
end

0 comments on commit 33c28f6

Please sign in to comment.