Allow an empty string for String#bytesplice

This commit is contained in:
dearblue
2023-04-15 21:26:01 +09:00
parent 59931e95c4
commit 8665f88791
2 changed files with 3 additions and 1 deletions
-1
View File
@@ -2966,7 +2966,6 @@ str_bytesplice(mrb_state *mrb, mrb_value str, mrb_int idx1, mrb_int len1, mrb_va
if (mrb_int_add_overflow(idx2, len2, &n) || RSTRING_LEN(replace) < n) {
len2 = RSTRING_LEN(replace) - idx2;
}
if (len2 == 0) return str;
mrb_str_modify(mrb, s);
if (len1 >= len2) {
memmove(RSTR_PTR(s)+idx1, RSTRING_PTR(replace)+idx2, len2);
+3
View File
@@ -963,4 +963,7 @@ assert('String#bytesplice') do
# check the negative length
assert_raise(IndexError) { "0123456789".bytesplice(3, -4, "ab") }
# with an empty string
assert_equal "012789", "0123456789".bytesplice(3, 4, "")
end