Skip to content

Commit

Permalink
lib/shell/command-processor.rb (Shell#[]): prevent unknown command
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
nagachika committed Oct 1, 2019
1 parent 8d5d5d5 commit d6adc68
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/shell/command-processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def test(command, file1, file2=nil)
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
Expand Down
18 changes: 18 additions & 0 deletions test/shell/test_command_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ def test_system_directory
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)
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#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
Expand Down

0 comments on commit d6adc68

Please sign in to comment.