Skip to content

Leave process stdio encodings alone when embedding IRB - #1285

Open
adityawrk wants to merge 1 commit into
ruby:masterfrom
adityawrk:fix/embedded-stdio-encoding
Open

adityawrk wants to merge 1 commit into
ruby:masterfrom
adityawrk:fix/embedded-stdio-encoding

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #1162.

RelineInputMethod calls set_encoding with override: false. That flag only chose which locale ivar to set; the method still ran set_encoding on $stdin, $stdout, and $stderr. Constructing the input method turned a stdout whose external encoding was nil into UTF-8, and a later ASCII-8BIT write of non-ASCII bytes raised Encoding::UndefinedConversionError. The same thing happens after binding.irb returns, so code that worked before the session fails after it.

override: false now only records the locale encoding. IRB's own copied stdout still uses that encoding, so the prompt path is unchanged. irb -E / irb -U pass override: true and still retarget the process streams.

Before this change, creating RelineInputMethod made $stdout.external_encoding UTF-8 and $stdout.write("日本語".b) raised. After it, $stdout.external_encoding stays nil, that write succeeds, and the input method's own stdout is UTF-8. The suite is 414 tests, 2593 assertions, with no failures.

RelineInputMethod called set_encoding with override: false, which still
ran set_encoding on $stdin, $stdout, and $stderr. A later binary write
then raised Encoding::UndefinedConversionError. override: false only
records the locale encoding for IRB's own IO copies. irb -E still
retargets the process streams.

This branch has not been deployed

No deployments
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.

IRB initialization changes global $stdout encoding, causing Encoding::UndefinedConversionError

1 participant