summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-24 01:50:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-24 01:50:09 +0000
commit5c9bc9f8e15c811aef9869ccee57a4812a3e6129 (patch)
tree2515279b804589800572a6c89ee5aa043d21013f /hash.c
parent47f3cc6e8b9ff973b73d49e4fb152ad576a3975b (diff)
hash.c: frozen PATH env
* 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
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/hash.c b/hash.c
index c509dee..69ffe75 100644
--- a/hash.c
+++ b/hash.c
@@ -2514,6 +2514,20 @@ env_str_new(const char *ptr, long len)
}
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
env_str_new2(const char *ptr)
{
if (!ptr) return Qnil;
@@ -2584,14 +2598,7 @@ rb_f_getenv(VALUE obj, VALUE name)
env = getenv(nam);
if (env) {
if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env)) {
-#ifdef _WIN32
- 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_path_str_new(env);
}
return env_str_new2(env);
}
@@ -2638,11 +2645,7 @@ env_fetch(int argc, VALUE *argv)
return if_none;
}
if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env))
-#ifdef _WIN32
- 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_path_str_new(env);
return env_str_new2(env);
}