mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Raise TypeError if calling ENV.freeze
Previously, you could call ENV.freeze, but it would not have the desired effect, as you could still modify ENV. Fixes [Bug #15920]
This commit is contained in:
parent
93328b5237
commit
f53d7e4bfd
2 changed files with 19 additions and 0 deletions
15
hash.c
15
hash.c
|
@ -5699,6 +5699,20 @@ env_reject(void)
|
|||
return rb_hash_delete_if(env_to_hash());
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ENV.freeze -> raises TypeError
|
||||
*
|
||||
* Ruby does not allow ENV to be frozen, so calling ENV.freeze
|
||||
* raises TypeError.
|
||||
*/
|
||||
static VALUE
|
||||
env_freeze(VALUE self)
|
||||
{
|
||||
rb_raise(rb_eTypeError, "cannot freeze ENV");
|
||||
return self; /* Not reached */
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ENV.shift -> Array or nil
|
||||
|
@ -6058,6 +6072,7 @@ Init_Hash(void)
|
|||
rb_define_singleton_method(envtbl, "filter", env_select, 0);
|
||||
rb_define_singleton_method(envtbl, "filter!", env_select_bang, 0);
|
||||
rb_define_singleton_method(envtbl, "shift", env_shift, 0);
|
||||
rb_define_singleton_method(envtbl, "freeze", env_freeze, 0);
|
||||
rb_define_singleton_method(envtbl, "invert", env_invert, 0);
|
||||
rb_define_singleton_method(envtbl, "replace", env_replace, 1);
|
||||
rb_define_singleton_method(envtbl, "update", env_update, 1);
|
||||
|
|
|
@ -496,6 +496,10 @@ class TestEnv < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_frozen
|
||||
assert_raise(TypeError) { ENV.freeze }
|
||||
end
|
||||
|
||||
def test_frozen
|
||||
ENV[PATH_ENV] = "/"
|
||||
ENV.each do |k, v|
|
||||
|
|
Loading…
Add table
Reference in a new issue