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

string.c: preserve coderange in String#setbyte

Fix a wrong jump so replacing a byte in an ASCII-only string with an
ASCII character won't clear the coderange.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
rhe 2017-07-06 07:21:17 +00:00
parent 2c8cec96cc
commit 06a3a10acf

View file

@ -5279,13 +5279,13 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
enc = STR_ENC_GET(str);
head = RSTRING_PTR(str);
ptr = &head[pos];
if (!STR_EMBEDDABLE_P(len, rb_enc_mbminlen(enc))) {
if (!STR_EMBED_P(str)) {
cr = ENC_CODERANGE(str);
switch (cr) {
case ENC_CODERANGE_7BIT:
left = ptr;
*ptr = byte;
if (ISASCII(byte)) break;
if (ISASCII(byte)) goto end;
nlen = rb_enc_precise_mbclen(left, head+len, enc);
if (!MBCLEN_CHARFOUND_P(nlen))
ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);