diff --git a/string.c b/string.c index a22505f592..35e53f7306 100644 --- a/string.c +++ b/string.c @@ -2742,6 +2742,7 @@ rb_str_concat(VALUE str1, VALUE str2) { unsigned int code; rb_encoding *enc = STR_ENC_GET(str1); + int encidx; if (FIXNUM_P(str2) || RB_TYPE_P(str2, T_BIGNUM)) { if (rb_num_to_uint(str2, &code) == 0) { @@ -2757,7 +2758,8 @@ rb_str_concat(VALUE str1, VALUE str2) return rb_str_append(str1, str2); } - if (enc == rb_usascii_encoding()) { + encidx = rb_enc_to_index(enc); + if (encidx == ENCINDEX_ASCII || encidx == ENCINDEX_US_ASCII) { /* US-ASCII automatically extended to ASCII-8BIT */ char buf[1]; buf[0] = (char)code; @@ -2765,8 +2767,8 @@ rb_str_concat(VALUE str1, VALUE str2) rb_raise(rb_eRangeError, "%u out of char range", code); } rb_str_cat(str1, buf, 1); - if (code > 127) { - rb_enc_associate_index(str1, rb_ascii8bit_encindex()); + if (encidx == ENCINDEX_US_ASCII && code > 127) { + rb_enc_associate_index(str1, ENCINDEX_ASCII); ENC_CODERANGE_SET(str1, ENC_CODERANGE_VALID); } }