diff --git a/src/string.c b/src/string.c index d9b973866..31cf47c04 100644 --- a/src/string.c +++ b/src/string.c @@ -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); diff --git a/test/t/string.rb b/test/t/string.rb index cb06be629..0bb9acfb3 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -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