summaryrefslogtreecommitdiff
path: root/test/ruby/test_sprintf.rb
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2024-10-22 19:22:37 -0700
committernagachika <nagachika@ruby-lang.org>2024-11-10 15:13:24 +0900
commit9bcc5c5fd9e8e4d15040eec6850b49d860eba621 (patch)
tree343a7b502d1ba69c56bcd9dba143686a1f806884 /test/ruby/test_sprintf.rb
parentee3428aa0e3a11ed1574b7d99222f6f08737f818 (diff)
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>
Diffstat (limited to 'test/ruby/test_sprintf.rb')
-rw-r--r--test/ruby/test_sprintf.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index c453ecd350..9b972dcbaa 100644
--- a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -543,4 +543,12 @@ class TestSprintf < Test::Unit::TestCase
sprintf("%*s", RbConfig::LIMITS["INT_MIN"], "")
end
end
+
+ def test_binary_format_coderange
+ 1.upto(500) do |i|
+ str = sprintf("%*s".b, i, "\xe2".b)
+ refute_predicate str, :ascii_only?
+ assert_equal i, str.bytesize
+ end
+ end
end