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

Fix bug when slicing a string with broken encoding

Commit aa2a428 introduced a bug where non-embedded string slices copied
the encoding of the original string. If the original string had a broken
encoding but the slice has valid encoding, then the slice would be
incorrectly marked as broken encoding.
This commit is contained in:
Peter Zhu 2022-09-27 14:54:09 -04:00
parent 6f8d17e43c
commit 28a572f8bf
Notes: git 2022-09-28 22:05:54 +09:00

View file

@ -2811,6 +2811,7 @@ str_subseq(VALUE str, long beg, long len)
}
else {
str2 = str_new_shared(rb_cString, str);
ENC_CODERANGE_CLEAR(str2);
RSTRING(str2)->as.heap.ptr += beg;
if (RSTRING(str2)->as.heap.len > len) {
RSTRING(str2)->as.heap.len = len;