summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-09-27 14:54:09 -0400
committerPeter Zhu <peter@peterzhu.ca>2022-09-28 09:05:23 -0400
commit28a572f8bffe54226a7ad3fae814c1c92b5036e6 (patch)
tree8d7149c66727c97c4f6366e3de53a6ef047c84b2 /string.c
parent6f8d17e43c7b9b3b8bf42df0ef1ca085080b65f0 (diff)
downloadruby-28a572f8bffe54226a7ad3fae814c1c92b5036e6.tar.gz
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.
Diffstat (limited to 'string.c')
-rw-r--r--string.c1
1 files changed, 1 insertions, 0 deletions
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;