StringScanner#skip returns nil inside an invalid character in non-UTF-8 strings (was an exception in 3.1.6)

オープン
#223 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
54/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, ruby
領域
backend

調査の方向性

Start by comparing StringScanner#skip behavior in the reported strscan versions for the Shift_JIS and UTF-16LE examples, then inspect the implementation and tests for skip on non-UTF-8 strings. Decide whether returning nil is intended or should raise consistently with the prior behavior; done means the behavior is specified and covered by regression tests, including the reported encodings.

索引モデルが issue の本文から書いたものです。

説明

Thanks for maintaining strscan.

On Ruby master (strscan 3.1.9.dev), StringScanner#skip returns nil when the scan position is inside an invalid or misaligned character in a non-UTF-8 string. strscan 3.1.6 (Ruby 4.0.9) raises there:

require "strscan"
[["/\xFF".dup.force_encoding("Shift_JIS"), "Shift_JIS"], ["/a".encode("UTF-16LE"), "UTF-16LE"]].each do |str, name|
  s = StringScanner.new(str)
  s.pos = 1
  p [name, (s.skip(/./) rescue $!.class)]
end
# master (strscan 3.1.9.dev): ["Shift_JIS", nil]            ["UTF-16LE", nil]
# 4.0.9  (strscan 3.1.6):     ["Shift_JIS", ArgumentError]  ["UTF-16LE", Encoding::CompatibilityError]

The same input as UTF-8 ("/\xFF", pos 1) raises ArgumentError on both.

Is returning nil here intended? We noticed it because Rails' route-path scanner advances with pos += 1 and then relies on skip(/./) either matching or raising. With nil, its loop never advances, so ActionDispatch::Journey::Parser.parse hangs on master for paths such as "/\xFF|bc" in Shift_JIS. Such paths are rare, and Rails could guard its loop. We'd just like to know whether the new result is deliberate before we propose anything there.


Found while comparing Rails' request path on Ruby master and Ruby 4.0.9 (record, part of my research project Lowrail).

主要言語
C
スター
88
フォーク
51
平均マージ
5日 2時間
マージ済み PR(30日)
2

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

ruby/strscan のほかの issue

ruby/strscan の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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