Skip to content

Fix FrozenError when parsing ERB files in Ruby 4.0#118

Merged
kou merged 1 commit intoruby-gettext:masterfrom
karinevieira:fix-frozen-string-error-ruby-4
Feb 25, 2026
Merged

Fix FrozenError when parsing ERB files in Ruby 4.0#118
kou merged 1 commit intoruby-gettext:masterfrom
karinevieira:fix-frozen-string-error-ruby-4

Conversation

@karinevieira
Copy link
Contributor

@karinevieira karinevieira commented Feb 24, 2026

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.

@kou kou merged commit ffe4341 into ruby-gettext:master Feb 25, 2026
27 of 31 checks passed
@kou
Copy link
Member

kou commented Feb 25, 2026

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants