Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRB fails to colorize code other than utf-8 #976

Open
tompng opened this issue Jun 23, 2024 · 0 comments
Open

IRB fails to colorize code other than utf-8 #976

tompng opened this issue Jun 23, 2024 · 0 comments

Comments

@tompng
Copy link
Member

tompng commented Jun 23, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant