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

process.c: argument types over conversion

* process.c (rb_exec_getargs): honor the expected argument types
  over the conversion method.  the basic language functionality
  should be robust.  [ruby-core:75388] [Bug #12355]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-05-06 22:58:03 +00:00
parent cc22facc9c
commit 48ed66868c
3 changed files with 38 additions and 2 deletions

View file

@ -1,3 +1,9 @@
Sat May 7 07:58:02 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (rb_exec_getargs): honor the expected argument types
over the conversion method. the basic language functionality
should be robust. [ruby-core:75388] [Bug #12355]
Fri May 6 08:16:26 2016 David Silva <david.silva@digital.cabinet-office.gov.uk>
* enum.c (enum_find): [DOC] add more examples to the documentation

View file

@ -1985,13 +1985,25 @@ rb_check_argv(int argc, VALUE *argv)
return prog;
}
static VALUE
check_hash(VALUE obj)
{
if (RB_SPECIAL_CONST_P(obj)) return Qnil;
switch (RB_BUILTIN_TYPE(obj)) {
case T_STRING:
case T_ARRAY:
return Qnil;
}
return rb_check_hash_type(obj);
}
static VALUE
rb_exec_getargs(int *argc_p, VALUE **argv_p, int accept_shell, VALUE *env_ret, VALUE *opthash_ret)
{
VALUE hash, prog;
if (0 < *argc_p) {
hash = rb_check_hash_type((*argv_p)[*argc_p-1]);
hash = check_hash((*argv_p)[*argc_p-1]);
if (!NIL_P(hash)) {
*opthash_ret = hash;
(*argc_p)--;
@ -1999,7 +2011,7 @@ rb_exec_getargs(int *argc_p, VALUE **argv_p, int accept_shell, VALUE *env_ret, V
}
if (0 < *argc_p) {
hash = rb_check_hash_type((*argv_p)[0]);
hash = check_hash((*argv_p)[0]);
if (!NIL_P(hash)) {
*env_ret = hash;
(*argc_p)--;

View file

@ -2256,4 +2256,22 @@ EOS
system(bin, "--disable=gems", "-w", "-e", "puts ARGV", *args)
end;
end
def test_to_hash_on_arguments
all_assertions do |a|
%w[Array String].each do |type|
a.for(type) do
assert_separately(['-', EnvUtil.rubybin], <<~"END;")
class #{type}
def to_hash
raise "[Bug-12355]: #{type}#to_hash is called"
end
end
ex = ARGV[0]
assert_equal(true, system([ex, ex], "-e", ""))
END;
end
end
end
end
end