diff options
-rw-r--r-- | string.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -4434,7 +4434,14 @@ rb_str_drop_bytes(VALUE str, long len) RSTRING(str)->as.heap.len = nlen; } ptr[nlen] = 0; - ENC_CODERANGE_CLEAR(str); + if (ENC_CODERANGE(str) == ENC_CODERANGE_VALID) { + int n = rb_enc_precise_mbclen(ptr, ptr + nlen, STR_ENC_GET(str)); + if (!MBCLEN_CHARFOUND_P(n)) + ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN); + } + else if (ENC_CODERANGE(str) == ENC_CODERANGE_BROKEN) { + ENC_CODERANGE_CLEAR(str); + } return str; } |