Skip to content

erb: fix Ractor::IsolationError - #156

Closed
altruby wants to merge 1 commit into
ruby:masterfrom
altruby:patch1
Closed

altruby wants to merge 1 commit into
ruby:masterfrom
altruby:patch1

Conversation

@altruby

@altruby altruby commented Dec 1, 2026

Copy link
Copy Markdown

This commit fixes a Ractor::IsolationError in
the following code:

Ractor.new do
  ERB::Util.escape_html("hello".encode("ISO-2022-JP"))
end.value

The CGI.escapeHTML method is used in this
codepath, and it is not Ractor-safe. The
fix avoids cgi.rb and converts the string
to UTF-8, escapes it, and then converts it
back to ISO-2022-JP before it is returned
to the caller.

When there is nothing to escape, the string
is returned as-is.

Another fix might be to make cgi.rb Ractor-safe,
or at least the method that erb uses.

This commit fixes a Ractor::IsolationError in
the following code:

```ruby
Ractor.new do
  ERB::Util.escape_html("hello".encode("ISO-2022-JP"))
end.value
```

The CGI.escapeHTML method is used in this
codepath, and it is not Ractor-safe. The
fix avoids cgi.rb and converts the string
to UTF-8, escapes it, and then converts it
back to ISO-2022-JP before it is returned
to the caller.

Another fix might be to make cgi.rb Ractor-safe,
or at least the method that erb uses.
@byroot

byroot commented Dec 1, 2026

Copy link
Copy Markdown
Member

Anything exotic like this is meant to be delegated by CGI. ERB only concerns itself with the happy path.

@byroot byroot closed this Dec 1, 2026
@altruby

altruby commented Dec 1, 2026

Copy link
Copy Markdown
Author

Thanks.
I opened a issue to track this on ruby-lang.org (can't open issues here).
https://bugs.ruby-lang.org/issues/22666

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