1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Bug #18955] Check length of argument for %c in proper encoding

This commit is contained in:
Nobuyoshi Nakada 2022-08-20 00:16:43 +09:00
parent 4177f60eed
commit ce384ef5a9
Notes: git 2022-08-20 03:57:48 +09:00
2 changed files with 5 additions and 2 deletions

View file

@ -441,10 +441,11 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
tmp = rb_check_string_type(val);
if (!NIL_P(tmp)) {
if (rb_enc_strlen(RSTRING_PTR(tmp),RSTRING_END(tmp),enc) != 1) {
rb_encoding *valenc = rb_enc_get(tmp);
if (rb_enc_strlen(RSTRING_PTR(tmp), RSTRING_END(tmp), valenc) != 1) {
rb_raise(rb_eArgError, "%%c requires a character");
}
c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, enc);
c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, valenc);
RB_GC_GUARD(tmp);
}
else {

View file

@ -892,6 +892,8 @@ class TestM17N < Test::Unit::TestCase
assert_raise(Encoding::CompatibilityError) {
"%s%s" % [s("\xc2\xa1"), e("\xc2\xa1")]
}
"%c" % "\u3042".encode('Windows-31J')
end
def test_sprintf_p