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

ruby-changes:58063

From: nagachika <ko1@a...>
Date: Tue, 1 Oct 2019 19:59:53 +0900 (JST)
Subject: [ruby-changes:58063] d6adc68dc9 (ruby_2_6): lib/shell/command-processor.rb (Shell#[]): prevent unknown command

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

From d6adc68dc9c74a33b3ca012af171e2d59f0dea10 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Tue, 1 Oct 2019 10:59:35 +0000
Subject: lib/shell/command-processor.rb (Shell#[]): prevent unknown command

`FileTest.send(command, ...)` allows to call not only FileTest-related
methods but also any method that belongs to Kernel, Object, etc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

diff --git a/lib/shell/command-processor.rb b/lib/shell/command-processor.rb
index 00357e0..82af76d 100644
--- a/lib/shell/command-processor.rb
+++ b/lib/shell/command-processor.rb
@@ -180,6 +180,9 @@ class Shell https://github.com/ruby/ruby/blob/trunk/lib/shell/command-processor.rb#L180
             top_level_test(command, file1)
           end
         else
+          unless FileTest.methods(false).include?(command.to_sym)
+            raise "unsupported command: #{ command }"
+          end
           if file2
             FileTest.send(command, file1, file2)
           else
diff --git a/test/shell/test_command_processor.rb b/test/shell/test_command_processor.rb
index d0bcf8e..7e1aa5b 100644
--- a/test/shell/test_command_processor.rb
+++ b/test/shell/test_command_processor.rb
@@ -68,6 +68,24 @@ class TestShell::CommandProcessor < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/shell/test_command_processor.rb#L68
     Dir.rmdir(path)
   end
 
+  def test_test
+    name = "foo#{exeext}"
+    path = File.join(@tmpdir, name)
+    open(path, "w", 0644) {}
+
+    assert_equal(true, @shell[?e, path])
+    assert_equal(true, @shell[:e, path])
+    assert_equal(true, @shell["e", path])
+    assert_equal(true, @shell[:exist?, path])
+    assert_equal(true, @shell["exist?", path])
+    assert_raise_with_message(RuntimeError, /unsupported command/) do
+      assert_equal(true, @shell[:instance_eval, path])
+    end
+  ensure
+    Process.waitall
+    File.unlink(path)
+  end
+
   def test_option_type
     name = 'foo.cmd'
     path = File.join(@tmpdir, name)
diff --git a/version.h b/version.h
index 2f3900a..2731a5c 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.5"
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 113
+#define RUBY_PATCHLEVEL 114
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 10
-- 
cgit v0.10.2


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

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