1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

include and prepend check no args

* eval.c (rb_mod_include, rb_mod_prepend): check if arguments are
  given, as well as Kernel#extend.  [ruby-dev:49854] [Bug #12887]
  [Fix GH-1470]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-11-06 05:42:53 +00:00
parent 2456f869c8
commit d2101310db
3 changed files with 21 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Sun Nov 6 14:42:50 2016 takkanm <takkanm@gmail.com>
* eval.c (rb_mod_include, rb_mod_prepend): check if arguments are
given, as well as Kernel#extend. [ruby-dev:49854] [Bug #12887]
[Fix GH-1470]
Sun Nov 6 11:59:05 2016 Shugo Maeda <shugo@ruby-lang.org> Sun Nov 6 11:59:05 2016 Shugo Maeda <shugo@ruby-lang.org>
* test/rinda/test_rinda.rb (test_make_socket_ipv6_multicast, * test/rinda/test_rinda.rb (test_make_socket_ipv6_multicast,

3
eval.c
View file

@ -1036,6 +1036,7 @@ rb_mod_include(int argc, VALUE *argv, VALUE module)
CONST_ID(id_append_features, "append_features"); CONST_ID(id_append_features, "append_features");
CONST_ID(id_included, "included"); CONST_ID(id_included, "included");
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
Check_Type(argv[i], T_MODULE); Check_Type(argv[i], T_MODULE);
while (argc--) { while (argc--) {
@ -1083,6 +1084,8 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module)
CONST_ID(id_prepend_features, "prepend_features"); CONST_ID(id_prepend_features, "prepend_features");
CONST_ID(id_prepended, "prepended"); CONST_ID(id_prepended, "prepended");
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
Check_Type(argv[i], T_MODULE); Check_Type(argv[i], T_MODULE);
while (argc--) { while (argc--) {

View file

@ -440,6 +440,10 @@ class TestModule < Test::Unit::TestCase
EOS EOS
end end
def test_include_with_no_args
assert_raise(ArgumentError) { Module.new { include } }
end
def test_included_modules def test_included_modules
assert_equal([], Mixin.included_modules) assert_equal([], Mixin.included_modules)
assert_equal([Mixin], User.included_modules) assert_equal([Mixin], User.included_modules)
@ -1868,6 +1872,10 @@ class TestModule < Test::Unit::TestCase
end; end;
end end
def test_prepend_module_with_no_args
assert_raise(ArgumentError) { Module.new { prepend } }
end
def test_class_variables def test_class_variables
m = Module.new m = Module.new
m.class_variable_set(:@@foo, 1) m.class_variable_set(:@@foo, 1)
@ -1934,6 +1942,10 @@ class TestModule < Test::Unit::TestCase
assert_equal(['public', 'protected'], list) assert_equal(['public', 'protected'], list)
end end
def test_extend_module_with_no_args
assert_raise(ArgumentError) { Module.new { extend } }
end
def test_invalid_attr def test_invalid_attr
%W[ %W[
foo? foo?