mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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:
parent
8eff476bce
commit
1a45b04482
3 changed files with 22 additions and 1 deletions
|
@ -180,6 +180,9 @@ class Shell
|
||||||
top_level_test(command, file1)
|
top_level_test(command, file1)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
unless FileTest.methods(false).include?(command.to_sym)
|
||||||
|
raise "unsupported command: #{ command }"
|
||||||
|
end
|
||||||
if file2
|
if file2
|
||||||
FileTest.send(command, file1, file2)
|
FileTest.send(command, file1, file2)
|
||||||
else
|
else
|
||||||
|
|
|
@ -66,4 +66,22 @@ class TestShell::CommandProcessor < Test::Unit::TestCase
|
||||||
Process.waitall
|
Process.waitall
|
||||||
Dir.rmdir(path)
|
Dir.rmdir(path)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.4.8"
|
#define RUBY_VERSION "2.4.8"
|
||||||
#define RUBY_RELEASE_DATE "2019-10-01"
|
#define RUBY_RELEASE_DATE "2019-10-01"
|
||||||
#define RUBY_PATCHLEVEL 360
|
#define RUBY_PATCHLEVEL 361
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2019
|
#define RUBY_RELEASE_YEAR 2019
|
||||||
#define RUBY_RELEASE_MONTH 10
|
#define RUBY_RELEASE_MONTH 10
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue