[Bug #18973] Promote US-ASCII to ASCII-8BIT when adding 8-bit char

This commit is contained in:
Nobuyoshi Nakada 2022-08-30 18:12:08 +09:00
parent 9dc60653db
commit 576bdec03f
Notes: git 2022-08-31 17:28:30 +09:00
4 changed files with 37 additions and 12 deletions

View file

@ -454,13 +454,18 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
str = tmp;
goto format_s1;
}
else {
n = NUM2INT(val);
if (n >= 0) n = rb_enc_codelen((c = n), enc);
}
n = NUM2INT(val);
if (n >= 0) n = rb_enc_codelen((c = n), enc);
if (n <= 0) {
rb_raise(rb_eArgError, "invalid character");
}
int encidx = rb_ascii8bit_appendable_encoding_index(enc, c);
if (encidx >= 0 && encidx != rb_enc_to_index(enc)) {
/* special case */
rb_enc_associate_index(result, encidx);
enc = rb_enc_from_index(encidx);
coderange = ENC_CODERANGE_VALID;
}
if (!(flags & FWIDTH)) {
CHECK(n);
rb_enc_mbcput(c, &buf[blen], enc);