Project

General

Profile

Actions

Bug #20185

closed

String#ascii_only? buggy in ruby 3.3

Added by chucke (Tiago Cardoso) 10 months ago. Updated 10 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:116203]

Description

This was the smallest reduction of the bug I could come up with:

require "stringio"

puts StringIO::VERSION

def is_ascii(buffer)
  str = buffer.string
  puts "\"#{str}\" is ascii: #{str.ascii_only?}"
end

buffer = StringIO.new("".b)

buffer.write("a=b&c=d")
buffer.rewind
is_ascii(buffer)
buffer.write "богус"
is_ascii(buffer)

# in ruby 3.3
#=> 3.1.0
#=> "a=b&c=d" is ascii: true
#=> "богус" is ascii: true

# in ruby 3.2
#=> 3.0.4
#=> "a=b&c=d" is ascii: true
#=> "богус" is ascii: true

# in ruby 3.1
#=> 3.0.1
#=> "a=b&c=d" is ascii: true
#=> "богус" is ascii: false

I believe that only the 3.1 result is correct, as "богус" first character is not ascii.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0