L1 · Ruby.wasm

ruby/ruby#21709 の再現

Ruby.wasm runtime を読み込み中…

再現スクリプト

prefix = '\p{In_Arabic}'
suffix = '\p{In_Arabic}'.encode('US-ASCII')

begin
  re = /#{prefix}#{suffix}/
  regexp_raised = nil
rescue => e
  regexp_raised = e.class.name
end

begin
  str = "#{prefix}#{suffix}"
  string_encoding = str.encoding.name
  string_raised = nil
rescue => e
  string_encoding = nil
  string_raised = e.class.name
end

$result = {
  ruby_version: RUBY_VERSION,
  regexp_built: regexp_raised.nil?,
  regexp_raised: regexp_raised,
  string_built: string_raised.nil?,
  string_encoding: string_encoding,
  string_raised: string_raised,
}

regexp_note =
  regexp_raised ? "raised #{regexp_raised}   <-- rejected" : 'built'
string_note =
  string_raised ? "raised #{string_raised}" : "built, encoding #{string_encoding}"

puts 'Interpolating the same two fragments, one UTF-8 and one US-ASCII:'
puts
puts '  Regexp   /#{prefix}#{suffix}/    ' + regexp_note
puts '  String   "#{prefix}#{suffix}"    ' + string_note
puts
if regexp_raised && string_raised.nil?
  puts 'The two forms disagree: Regexp interpolation rejects the mixed'
  puts 'encodings that String interpolation silently upgrades.'
else
  puts 'The two forms agree on how to combine fragments of different encodings.'
end
puts "Ruby #{RUBY_VERSION}"

baseline の出力

Initialising…
(待機中)

fix 候補の出力

(fix 候補はまだありません — bugs.ruby-lang.org#21709 は upstream で未解決)