1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix String#partition

Split with the matched part when the separator matches the empty
part at the beginning.  [Bug #11014]
This commit is contained in:
Nobuyoshi Nakada 2020-01-16 15:36:38 +09:00
parent 0b6682dc57
commit fce54a5404
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 2 additions and 1 deletions

View file

@ -9795,7 +9795,6 @@ rb_str_partition(VALUE str, VALUE sep)
return rb_ary_new3(3, rb_str_dup(str), str_new_empty(str), str_new_empty(str));
}
sep = rb_str_subpat(str, sep, INT2FIX(0));
if (pos == 0 && RSTRING_LEN(sep) == 0) goto failed;
}
else {
pos = rb_str_index(str, sep, 0);

View file

@ -2567,6 +2567,8 @@ CODE
hello = "hello"
hello.partition("hi").map(&:upcase!)
assert_equal("hello", hello, bug)
assert_equal(["", "", "foo"], "foo".partition(/^=*/))
end
def test_rpartition