ruby / ruby/irb

IRB fails to colorize code other than utf-8

Open
#976 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
478
Forks
158
Avg merge
1d 12h
Merged PRs (30d)
12

Description

Description

Create a ruby script with File.write("a.rb", "# coding: sjis\nbinding.irb\n__END__\nあ".encode("sjis"))
Run ruby a.rb
IRB fails to colorize code around binding.irb

ruby -e 'File.write("a.rb", "# coding: sjis\nbinding.irb\n__END__\nあ".encode("sjis"))'
ruby a.rb
/Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/reline-0.5.9/lib/reline/unicode.rb:52:in `ord': invalid byte sequence in UTF-8 (ArgumentError)
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/reline-0.5.9/lib/reline/unicode.rb:52:in `block in escape_for_print'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/reline-0.5.9/lib/reline/unicode.rb:45:in `map!'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/reline-0.5.9/lib/reline/unicode.rb:45:in `escape_for_print'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/color.rb:139:in `block in colorize_code'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/color.rb:192:in `block (2 levels) in scan'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/color.rb:204:in `block (2 levels) in scan'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/color.rb:202:in `each'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/color.rb:202:in `block in scan'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/ruby-lex.rb:57:in `rescue in compile_with_errors_suppressed'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/ruby-lex.rb:46:in `compile_with_errors_suppressed'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/color.rb:179:in `scan'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/color.rb:136:in `colorize_code'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb/workspace.rb:161:in `code_around_binding'
	from /Users/tomoya.ishida/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.13.2/lib/irb.rb:1584:in `irb'
	from <internal:prelude>:5:in `irb'
	from a.rb:1:in `<main>'
Combination
# encoding: utf-8 and file: sjis
File.write("a.rb", "binding.irb\n__END__\nあ".encode("sjis")) # error

# encoding: sjis and file: sjis
File.write("b.rb", "# coding: sjis\ns='あ'\nbinding.irb".encode("sjis")) # no error
File.write("c.rb", "# coding: sjis\nbinding.irb\n__END__\nあ".encode("sjis")) # error

# encoding: sjis and file: utf-8
File.write("d.rb", "# coding: sjis\nbinding.irb\n__END__\nあ") # no error

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied encoding cases with binding.irb, then trace irb/color.rb and reline/unicode.rb at the stack-trace locations. Compare the failing and non-failing combinations, and consider the issue complete when IRB no longer raises while colorizing code from the failing Shift_JIS cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.