mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[Bug #18958] format string must be ASCII compatible
This commit is contained in:
parent
43e8d9a050
commit
1a2f99275b
Notes:
git
2022-08-20 10:07:00 +09:00
2 changed files with 11 additions and 0 deletions
|
@ -250,6 +250,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
|||
--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);
|
||||
|
|
|
@ -898,6 +898,16 @@ class TestM17N < Test::Unit::TestCase
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue