Bug #20883
closedsprintf with binary strings has incorrect coderange
Description
In 9dc6065 we stopped updating the coderange when the encoding became ENCINDEX_ASCII_8BIT. Though ASCII-8BIT (binary) can't ever have a broken coderange, it does need to distinguish between 7bit and valid.
puts ("%s" % "\xe2".b).ascii_only?
# => false from Ruby 2.1 to 3.1
# => true (incorrect) on Ruby 3.2 and 3.3
# => false again on HEAD
This was fixed in master as part of #20189, which clears the coderange in more cases of rb_str_resize
which happens to fix this, but we shouldn't rely on it.
Updated by jhawthorn (John Hawthorn) about 2 months ago
- Status changed from Open to Closed
Applied in changeset git|1f6dd9071c7994dd639d2e1cf2fe04e944173f17.
Fix update_coderange for binary strings
Although a binary (aka ASCII-8BIT) string will never have a broken
coderange, it still has to differentiate between "valid" and "7bit".
On Ruby 3.4/trunk this problem is masked because we now clear the
coderange more agressively in rb_str_resize, and we happened to always
be strinking this string, but we should not assume that.
On Ruby 3.3 this created strings where ascii_only?
was true in cases
it shouldn't be as well as other problems.
Fixes [Bug #20883]
Co-authored-by: Daniel Colson danieljamescolson@gmail.com
Co-authored-by: Matthew Draper matthew@trebex.net
Updated by jhawthorn (John Hawthorn) about 2 months ago
I opened two backport PRs. I marked 3.2 and 3.3 as REQUIRED for backport, but the bug is fairly mild if the branch maintainers would rather skip it.
3.2: https://github.com/ruby/ruby/pull/12041
3.3: https://github.com/ruby/ruby/pull/12040
Updated by nagachika (Tomoyuki Chikanaga) about 2 months ago
- Backport changed from 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: DONTNEED, 3.2: DONE, 3.3: REQUIRED
ruby_3_2 9bcc5c5fd9e8e4d15040eec6850b49d860eba621.
Updated by nagachika (Tomoyuki Chikanaga) about 2 months ago
Merged the PR for ruby_3_2 at 9bcc5c5fd9e8e4d15040eec6850b49d860eba621. Thank you for the PRs.