[ruby-core:116203] [Ruby master Bug#20185] String#ascii_only? buggy in ruby 3.3

Issue #20185 has been reported by chucke (Tiago Cardoso). ---------------------------------------- Bug #20185: String#ascii_only? buggy in ruby 3.3 https://bugs.ruby-lang.org/issues/20185 * Author: chucke (Tiago Cardoso) * Status: Open * Priority: Normal * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/

Issue #20185 has been updated by andrykonchin (Andrew Konchin). I cannot reproduce the issue with plain String (without StringIO) on Ruby 3.2, 3.1 and 3.0. `ascii_only?` reports `false` for "богус": ``` ruby -e 'p "богус".ascii_only?' false ``` I believe in the examples involving StringIO the observed behaviour is caused by preserving `StringIO#string`'s encoding. StringIO instance is initialised with a String literal in `binary` encoding. And any modification like writing doesn't change encoding even when a UTF-8 String is written: ```ruby io = StringIO.new "".b io.string.encoding # => #<Encoding:ASCII-8BIT> io.write "汉" io.string.encoding # => #<Encoding:ASCII-8BIT> ``` ---------------------------------------- Bug #20185: String#ascii_only? buggy in ruby 3.3 https://bugs.ruby-lang.org/issues/20185#change-106230 * Author: chucke (Tiago Cardoso) * Status: Open * Priority: Normal * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/

Issue #20185 has been updated by chucke (Tiago Cardoso). nobu, can I ask why was the ticket closed? Even considering the comment from andrykonchin, he clearly points oot at the end that there are bytes greater than 128 in the string (therefore `.ascii_only?` should be false). ---------------------------------------- Bug #20185: String#ascii_only? buggy in ruby 3.3 https://bugs.ruby-lang.org/issues/20185#change-106255 * Author: chucke (Tiago Cardoso) * Status: Closed * Priority: Normal * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/

Issue #20185 has been updated by jeremyevans0 (Jeremy Evans). chucke (Tiago Cardoso) wrote in #note-3:
nobu, can I ask why was the ticket closed? Even considering the comment from andrykonchin, he clearly points oot at the end that there are bytes greater than 128 in the string (therefore `.ascii_only?` should be false).
This was fixed by commit:6283ae8d369bd2f8a022bb69bc5b742c58529dec ---------------------------------------- Bug #20185: String#ascii_only? buggy in ruby 3.3 https://bugs.ruby-lang.org/issues/20185#change-106256 * Author: chucke (Tiago Cardoso) * Status: Closed * Priority: Normal * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/

Issue #20185 has been updated by chucke (Tiago Cardoso). Apologies everyone, got temporary redmine visual impairment. Thank you. ---------------------------------------- Bug #20185: String#ascii_only? buggy in ruby 3.3 https://bugs.ruby-lang.org/issues/20185#change-106258 * Author: chucke (Tiago Cardoso) * Status: Closed * Priority: Normal * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/

Issue #20185 has been updated by Eregon (Benoit Daloze). Indeed on Redmine I see no link to the commit in https://bugs.ruby-lang.org/issues/20185?tab=history#note-2, it seems like a bug. ---------------------------------------- Bug #20185: String#ascii_only? buggy in ruby 3.3 https://bugs.ruby-lang.org/issues/20185#change-106260 * Author: chucke (Tiago Cardoso) * Status: Closed * Priority: Normal * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/

Issue #20185 has been updated by hsbt (Hiroshi SHIBATA). No, `Fix https://bugs.ruby-lang.org/issues/20185`of commit message is not correct format for redmine autolink. ---------------------------------------- Bug #20185: String#ascii_only? buggy in ruby 3.3 https://bugs.ruby-lang.org/issues/20185#change-106281 * Author: chucke (Tiago Cardoso) * Status: Closed * Priority: Normal * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/
participants (5)
-
andrykonchin (Andrew Konchin)
-
chucke (Tiago Cardoso)
-
Eregon (Benoit Daloze)
-
hsbt (Hiroshi SHIBATA)
-
jeremyevans0 (Jeremy Evans)