ruby-changes:73759
From: Peter <ko1@a...>
Date: Wed, 28 Sep 2022 22:05:47 +0900 (JST)
Subject: [ruby-changes:73759] 28a572f8bf (master): Fix bug when slicing a string with broken encoding
https://git.ruby-lang.org/ruby.git/commit/?id=28a572f8bf From 28a572f8bffe54226a7ad3fae814c1c92b5036e6 Mon Sep 17 00:00:00 2001 From: Peter Zhu <peter@p...> 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(+) 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) https://github.com/ruby/ruby/blob/trunk/string.c#L2811 } 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.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/