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

ruby-changes:57939

From: Jeremy <ko1@a...>
Date: Fri, 27 Sep 2019 00:02:16 +0900 (JST)
Subject: [ruby-changes:57939] 47d44510a3 (master): Fix more keyword argument separation issues in Pathname

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

From 47d44510a3f5c6cfca69b3fc05d7f5f35b1b2784 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Wed, 25 Sep 2019 15:32:35 -0700
Subject: Fix more keyword argument separation issues in Pathname


diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index 022a876..75d04d0 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -434,7 +434,7 @@ path_write(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L434
 
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
-    return rb_funcallv(rb_cFile, id_write, 1+n, args);
+    return rb_funcallv_kw(rb_cFile, id_write, 1+n, args, RB_PASS_CALLED_KEYWORDS);
 }
 
 /*
@@ -455,7 +455,7 @@ path_binwrite(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L455
 
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
-    return rb_funcallv(rb_cFile, id_binwrite, 1+n, args);
+    return rb_funcallv_kw(rb_cFile, id_binwrite, 1+n, args, RB_PASS_CALLED_KEYWORDS);
 }
 
 /*
@@ -477,7 +477,7 @@ path_readlines(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L477
 
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
-    return rb_funcallv(rb_cFile, id_readlines, 1+n, args);
+    return rb_funcallv_kw(rb_cFile, id_readlines, 1+n, args, RB_PASS_CALLED_KEYWORDS);
 }
 
 /*
@@ -678,10 +678,10 @@ path_open(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L678
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
     if (rb_block_given_p()) {
-        return rb_block_call(rb_cFile, id_open, 1+n, args, 0, 0);
+        return rb_block_call_kw(rb_cFile, id_open, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
     }
     else {
-        return rb_funcallv(rb_cFile, id_open, 1+n, args);
+        return rb_funcallv_kw(rb_cFile, id_open, 1+n, args, RB_PASS_CALLED_KEYWORDS);
     }
 }
 
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 053c728..39c792d 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -745,6 +745,14 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L745
     }
   end
 
+  def test_readlines_opts
+    with_tmpchdir('rubytest-pathname') {|dir|
+      open("a", "w") {|f| f.puts 1, 2 }
+      a = Pathname("a").readlines 1, chomp: true
+      assert_equal(["1", "", "2", ""], a)
+    }
+  end
+
   def test_read
     with_tmpchdir('rubytest-pathname') {|dir|
       open("a", "w") {|f| f.puts 1, 2 }
@@ -769,6 +777,14 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L777
     }
   end
 
+  def test_write_opts
+    with_tmpchdir('rubytest-pathname') {|dir|
+      path = Pathname("a")
+      path.write "abc", mode: "w"
+      assert_equal("abc", path.read)
+    }
+  end
+
   def test_binwrite
     with_tmpchdir('rubytest-pathname') {|dir|
       path = Pathname("a")
@@ -777,6 +793,14 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L793
     }
   end
 
+  def test_binwrite_opts
+    with_tmpchdir('rubytest-pathname') {|dir|
+      path = Pathname("a")
+      path.binwrite "abc\x80", mode: 'w'
+      assert_equal("abc\x80".b, path.binread)
+    }
+  end
+
   def test_sysopen
     with_tmpchdir('rubytest-pathname') {|dir|
       open("a", "w") {|f| f.write "abc" }
@@ -929,6 +953,10 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L953
         assert_equal("abc", f.read)
       }
 
+      path.open(mode: "r") {|f|
+        assert_equal("abc", f.read)
+      }
+
       Pathname("b").open("w", 0444) {|f| f.write "def" }
       assert_equal(0444 & ~File.umask, File.stat("b").mode & 0777)
       assert_equal("def", File.read("b"))
@@ -940,6 +968,10 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L968
       g = path.open
       assert_equal("abc", g.read)
       g.close
+
+      g = path.open(mode: "r")
+      assert_equal("abc", g.read)
+      g.close
     }
   end
 
-- 
cgit v0.10.2


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

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