mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Allow an empty string for String#bytesplice
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user