IRB fails to colorize code other than utf-8

未关闭
#976 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
ruby
领域
cli

调研方向

使用 binding.irb 重现提供的编码案例,然后在堆栈跟踪所示的位置跟踪 irb/color.rb 和 reline/unicode.rb。比较失败和不失败的组合,并在 IRB 对失败的 Shift_JIS 案例中的代码进行着色时不再引发异常后,认为该 issue 已完成。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Ruby
星标
477
派生
165
平均合并
1 天 19 小时
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/irb 的其他 Issue

查看 ruby/irb 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。