Prism::Translation::RubyParser may fail to parse code containing multibyte characters

オープン 初心者向け
#4,369 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ruby
領域
backend

調査の方向性

lib/prism/translation/ruby_parser.rbから始め、特に報告されたgap.match?呼び出し付近のCompiler#attach_commentsを確認してください。issueにある2つのRubyParser.parse入力で失敗を再現し、その後、近くのコメント付与ロジックと関連する既存テストを調べてください。完了条件は、最初のケースがコメントテキストのみを返し、2つ目のケースが例外を発生させずにパースされることです。

索引モデルが 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分
マージ済み PR(30日)
85

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/prism のほかの issue

ruby/prism の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。