ruby-changes:72989
From: Nobuyoshi <ko1@a...>
Date: Sat, 20 Aug 2022 10:06:54 +0900 (JST)
Subject: [ruby-changes:72989] 1a2f99275b (master): [Bug #18958] format string must be ASCII compatible
https://git.ruby-lang.org/ruby.git/commit/?id=1a2f99275b From 1a2f99275be28fb0e8ff4cfc0165966e99898d70 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 19 Aug 2022 23:53:33 +0900 Subject: [Bug #18958] format string must be ASCII compatible --- sprintf.c | 1 + test/ruby/test_m17n.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/sprintf.c b/sprintf.c index f7ebe82e2c..22323265b3 100644 --- a/sprintf.c +++ b/sprintf.c @@ -250,6 +250,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L250 --argv; StringValue(fmt); enc = rb_enc_get(fmt); + rb_must_asciicompat(fmt); orig = fmt; fmt = rb_str_tmp_frozen_acquire(fmt); p = RSTRING_PTR(fmt); diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index a50507a528..da04ae7fa7 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -898,6 +898,16 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L898 def test_sprintf_p Encoding.list.each do |e| + unless e.ascii_compatible? + format = e.dummy? ? "%p".force_encoding(e) : "%p".encode(e) + assert_raise(Encoding::CompatibilityError) do + sprintf(format, nil) + end + assert_raise(Encoding::CompatibilityError) do + format % nil + end + next + end format = "%p".force_encoding(e) ['', 'a', "\xC2\xA1", "\x00"].each do |s| s.force_encoding(e) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/