Skip to content

Conversation

jsxs0
Copy link
Contributor

@jsxs0 jsxs0 commented Jun 5, 2025

Description

Fixes encoding crash when LANG= (empty) by using String#scrub to handle invalid characters gracefully.

Problem

When LANG=, debugger crashes with Encoding::CompatibilityError on history files with UTF-8 characters.

Solution

Use String#scrub to clean problematic characters instead of forcing UTF-8 encoding.

Testing

  • LANG= ruby -e 'require "debug"; debugger' now works
  • Respects system encoding preferences

Fixes #1131

@ko1
Copy link
Collaborator

ko1 commented Jun 5, 2025

irb seems to handle encoding, but it is not stuck on UTF-8.

ko1@WSL2 ~/ruby/gems/debug
[master]$ irb
irb(main):001> 'あいうえお'
=> "あいうえお"
irb(main):002>

[master]$ tail ~/.irb_history
...
'あいうえお'

[master]$ LANG=C irb
irb(main):001> '???????????????'
=> "???????????????"
irb(main):002>

So I think

  • respect LANG at the writing timing (so the patch is too much)
  • use String#scrub to prevent hung

seems better.

@jsxs0
Copy link
Contributor Author

jsxs0 commented Jun 5, 2025

@ko1 Fixed! Using String#scrub now. Thanks!

@ko1
Copy link
Collaborator

ko1 commented Jun 5, 2025

Thank you!!

Copy link

launchable-app bot commented Jun 5, 2025

Tests Failed

✖️no tests failed ✔️74 tests passed(2 flakes)

@ko1 ko1 force-pushed the fix/encoding-error-empty-lang branch from 6cbefbd to 209f492 Compare June 5, 2025 08:24
@ko1 ko1 merged commit bd9a813 into ruby:master Jun 5, 2025
28 of 32 checks passed
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.

If the environment variable LANG is empty, the debugger command will error
2 participants