ruby-changes:59710
From: Nobuyoshi <ko1@a...>
Date: Thu, 16 Jan 2020 15:45:01 +0900 (JST)
Subject: [ruby-changes:59710] fce54a5404 (master): Fix `String#partition`
https://git.ruby-lang.org/ruby.git/commit/?id=fce54a5404 From fce54a5404139a77bd0b7d6f82901083fcb16f1e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 16 Jan 2020 15:36:38 +0900 Subject: Fix `String#partition` Split with the matched part when the separator matches the empty part at the beginning. [Bug #11014] diff --git a/string.c b/string.c index 2413fbf..ca425e9 100644 --- a/string.c +++ b/string.c @@ -9795,7 +9795,6 @@ rb_str_partition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L9795 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); diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 09d099b..f0b7653 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -2567,6 +2567,8 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L2567 hello = "hello" hello.partition("hi").map(&:upcase!) assert_equal("hello", hello, bug) + + assert_equal(["", "", "foo"], "foo".partition(/^=*/)) end def test_rpartition -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/