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.
patched by <mame@ruby-lang.org>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@67820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2019-10-01 11:06:17 +00:00
parent 8eff476bce
commit 1a45b04482
3 changed files with 22 additions and 1 deletions

View file

@ -180,6 +180,9 @@ class Shell
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

View file

@ -66,4 +66,22 @@ class TestShell::CommandProcessor < Test::Unit::TestCase
Process.waitall
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
end

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.4.8"
#define RUBY_RELEASE_DATE "2019-10-01"
#define RUBY_PATCHLEVEL 360
#define RUBY_PATCHLEVEL 361
#define RUBY_RELEASE_YEAR 2019
#define RUBY_RELEASE_MONTH 10