From 28a572f8bffe54226a7ad3fae814c1c92b5036e6 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 27 Sep 2022 14:54:09 -0400 Subject: 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. --- string.c | 1 + 1 file changed, 1 insertion(+) (limited to 'string.c') diff --git a/string.c b/string.c index bdab6fa143..78ac5591cc 100644 --- a/string.c +++ b/string.c @@ -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; -- cgit v1.2.3