Skip to content

Commit

Permalink
Fix String#partition
Browse files Browse the repository at this point in the history
Split with the matched part when the separator matches the empty
part at the beginning.  [Bug #11014]
  • Loading branch information
nobu committed Jan 16, 2020
1 parent 0b6682d commit fce54a5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 0 additions & 1 deletion string.c
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_string.rb
Expand Up @@ -2567,6 +2567,8 @@ def (hyphen = Object.new).to_str; "-"; end
hello = "hello"
hello.partition("hi").map(&:upcase!)
assert_equal("hello", hello, bug)

assert_equal(["", "", "foo"], "foo".partition(/^=*/))
end

def test_rpartition
Expand Down

0 comments on commit fce54a5

Please sign in to comment.