Prism::Translation::RubyParser may fail to parse code containing multibyte characters
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从lib/prism/translation/ruby_parser.rb开始,重点查看报告中gap.match?调用附近的Compiler#attach_comments。使用 issue 中的两个RubyParser.parse输入重现故障,然后检查附近的注释附加逻辑和相关的现有测试。完成标准是:第一个情况只返回注释文本,第二个情况解析时不抛出异常。
由索引模型根据 Issue 内容生成。
描述
Prism::Translation::RubyParser may fail to parse code containing multibyte characters (e.g. CJK).
Reproduction
- Ruby: 4.0.9
- Prism: 05aa35a (same for v2.1.0)
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'prism', github: 'ruby/prism', ref: '05aa35afebb26ee8c11f7fc393065d4f0ba0b6f2'
gem 'sexp_processor'
end
# does not raise an error but parsed comments contain both multibyte chars and def
r = Prism::Translation::RubyParser.parse("# ああああああ\ndef x; end\n")
p r.comments #=> "# ああああああ\ndef x; end\n"
# raises NoMethodError
Prism::Translation::RubyParser.parse("# あああああああ\ndef x; end\n")
Result:
"# ああああああ\ndef x; end\n"
/path/to/prism-05aa35afebb2/lib/prism/translation/ruby_parser.rb:1580:in 'block in Prism::Translation::RubyParser::Compiler#attach_comments': undefined method 'match?' for nil (NoMethodError)
if gap.match?(/\S/)
^^^^^^^
from /path/to/prism-05aa35afebb2/lib/prism/translation/ruby_parser.rb:1577:in 'Array#reverse_each'
from /path/to/prism-05aa35afebb2/lib/prism/translation/ruby_parser.rb:1577:in 'Prism::Translation::RubyParser::Compiler#attach_comments'
from /path/to/prism-05aa35afebb2/lib/prism/translation/ruby_parser.rb:544:in 'Prism::Translation::RubyParser::Compiler#visit_def_node'
(snip)
Expectation
- In the first case, it returns
"# ああああああ\n" - In the second case, no error raises
- 主要语言
- C
- 星标
- 1k
- 派生
- 202
- 平均合并
- 5 小时 55 分钟
- 30 天内合并 PR
- 85
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/prism 的其他 Issue
-
Prism::Translation::Parser raises NoMethodError for a method with a &nil parameter and a body可能已有人在做 @bbatsov 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Heredoc and outer-context recovery at recursion depth / stack budget limit causes location underflow未关闭
难度 4/5 3-5 天 新手友好度 43/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 1/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
area: recompiler area: runtime kind: bug preview-effort: small priority: low
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100