[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 2025-04-09 13:49:37 +00: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 {