[前][次][番号順一覧][スレッド一覧]

ruby-changes:56676

From: Nobuyoshi <ko1@a...>
Date: Sat, 27 Jul 2019 22:16:51 +0900 (JST)
Subject: [ruby-changes:56676] Nobuyoshi Nakada: f1b76ea63c (master): Occupy match data

https://git.ruby-lang.org/ruby.git/commit/?id=f1b76ea63c

From f1b76ea63ce40670071a857f408a4747c571f1e9 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 27 Jul 2019 21:54:34 +0900
Subject: Occupy match data

* string.c (rb_str_split_m): occupy match data not to be modified
  during yielding the block.  [Bug #16024]

diff --git a/string.c b/string.c
index fcaf280..2805b4d 100644
--- a/string.c
+++ b/string.c
@@ -8087,7 +8087,9 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L8087
 	struct re_registers *regs;
 
 	while ((end = rb_reg_search(spat, str, start, 0)) >= 0) {
-	    regs = RMATCH_REGS(rb_backref_get());
+            VALUE match = rb_backref_get();
+            if (!result) rb_match_busy(match);
+            regs = RMATCH_REGS(match);
 	    if (start == end && BEG(0) == END(0)) {
 		if (!ptr) {
 		    SPLIT_STR(0, 0);
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 611bb79..7ae3bf2 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1779,6 +1779,9 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1779
 
     result = []; "".split(//, 1) {|s| result << s}
     assert_equal([], result)
+
+    result = []; "aaa,bbb,ccc,ddd".split(/,/) {|s| result << s.gsub(/./, "A")}
+    assert_equal(["AAA"]*4, result)
   ensure
     EnvUtil.suppress_warning {$; = fs}
   end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]