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

Đang mở
#223 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
54/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, ruby
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
C
Star
88
Fork
51
Merge trung bình
5 ngày 2 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby/strscan

Tất cả issue của ruby/strscan

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.