ruby/lib/prism/polyfill/scan_byte.rb
Earlopain 970813d982 [ruby/prism] Fix parser translator during string escaping with invalid utf-8
Instead, prefer `scan_byte` over `get_byte` since that already returns the byte as an integer, sidestepping conversion issues.

Fixes https://github.com/ruby/prism/issues/3582

7f3008b2b5
2025-06-11 18:07:43 +00:00

14 lines
304 B
Ruby

# frozen_string_literal: true
require "strscan"
# Polyfill for StringScanner#scan_byte, which didn't exist until Ruby 3.4.
if !(StringScanner.instance_methods.include?(:scan_byte))
StringScanner.include(
Module.new {
def scan_byte # :nodoc:
get_byte&.b&.ord
end
}
)
end