* hash.c (env_path_str_new): make PATH environment variable
  string, to be frozen.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-06-24 01:50:09 +00:00
Родитель 47f3cc6e8b
Коммит 5c9bc9f8e1
3 изменённых файлов: 39 добавлений и 13 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Jun 24 10:50:06 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* hash.c (env_path_str_new): make PATH environment variable
string, to be frozen.
Tue Jun 24 10:40:52 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com> Tue Jun 24 10:40:52 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* tool/make-snapshot: download bundle gems when package making. * tool/make-snapshot: download bundle gems when package making.

29
hash.c
Просмотреть файл

@ -2513,6 +2513,20 @@ env_str_new(const char *ptr, long len)
return str; return str;
} }
static VALUE
env_path_str_new(const char *ptr)
{
#ifdef _WIN32
VALUE str = rb_enc_str_new_cstr(ptr, rb_utf8_encoding());
str = rb_str_conv_enc(str, NULL, rb_filesystem_encoding());
#else
VALUE str = rb_filesystem_str_new_cstr(ptr);
#endif
rb_obj_freeze(str);
return str;
}
static VALUE static VALUE
env_str_new2(const char *ptr) env_str_new2(const char *ptr)
{ {
@ -2584,14 +2598,7 @@ rb_f_getenv(VALUE obj, VALUE name)
env = getenv(nam); env = getenv(nam);
if (env) { if (env) {
if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env)) { if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env)) {
#ifdef _WIN32 return env_path_str_new(env);
VALUE str = rb_str_conv_enc(rb_str_new(env, strlen(env)), rb_utf8_encoding(), rb_filesystem_encoding());
#else
VALUE str = rb_filesystem_str_new_cstr(env);
#endif
rb_obj_freeze(str);
return str;
} }
return env_str_new2(env); return env_str_new2(env);
} }
@ -2638,11 +2645,7 @@ env_fetch(int argc, VALUE *argv)
return if_none; return if_none;
} }
if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env)) if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env))
#ifdef _WIN32 return env_path_str_new(env);
return rb_str_conv_enc(rb_str_new(env, strlen(env)), rb_utf8_encoding(), rb_filesystem_encoding());
#else
return rb_filesystem_str_new_cstr(env);
#endif
return env_str_new2(env); return env_str_new2(env);
} }

Просмотреть файл

@ -408,4 +408,22 @@ class TestEnv < Test::Unit::TestCase
keys.each {|k| ENV.delete(k)} keys.each {|k| ENV.delete(k)}
end end
end end
def test_frozen
ENV[PATH_ENV] = "/"
ENV.each do |k, v|
assert_predicate(k, :frozen?)
assert_predicate(v, :frozen?)
end
ENV.each_key do |k|
assert_predicate(k, :frozen?)
end
ENV.each_value do |v|
assert_predicate(v, :frozen?)
end
ENV.each_key do |k|
assert_predicate(ENV[k], :frozen?, "[#{k.dump}]")
assert_predicate(ENV.fetch(k), :frozen?, "fetch(#{k.dump})")
end
end
end end