Skip to content

Commit ffe4341

Browse files
authored
Fix FrozenError when parsing ERB files in Ruby 4.0 (#118)
Running `rake gettext:find` on Ruby 4.0 projects fails with the following error: ``` FrozenError: can't modify frozen String: "#coding:UTF-8\n_erbout = +''; _erbout.<< "<h2>".freeze; ``` In Ruby 4.0, `ERB#src` now returns a frozen String. `GetText::ErbParser#parse` calls src.force_encoding(encoding) directly on that value, which raises a FrozenError. To fix that, we're using the unary + operator (`+erb.src`) to get a mutable copy of the string.
1 parent 45228ed commit ffe4341

File tree

1 file changed

+1
-1
lines changed
  • lib/gettext/tools/parser

1 file changed

+1
-1
lines changed

lib/gettext/tools/parser/erb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def parse
7070
else
7171
erb = ERB.new(content, nil, "-")
7272
end
73-
src = erb.src
73+
src = +erb.src
7474

7575
# Force the src encoding back to the encoding in magic comment
7676
# or original content.

0 commit comments

Comments
 (0)