diff options
-rw-r--r-- | hash.c | 4 | ||||
-rw-r--r-- | test/ruby/test_env.rb | 10 |
2 files changed, 13 insertions, 1 deletions
@@ -5102,6 +5102,8 @@ ruby_setenv(const char *name, const char *value) ENV_LOCK(); { + /* Use _wputenv_s() instead of SetEnvironmentVariableW() to make sure + * special variables like "TZ" are interpret by libc. */ failed = _wputenv_s(wname, wvalue); } ENV_UNLOCK(); @@ -5111,7 +5113,7 @@ ruby_setenv(const char *name, const char *value) * variable from the system area. */ if (!value || !*value) { /* putenv() doesn't handle empty value */ - if (!SetEnvironmentVariable(name, value) && + if (!SetEnvironmentVariableW(wname, value ? wvalue : NULL) && GetLastError() != ERROR_ENVVAR_NOT_FOUND) goto fail; } if (failed) { diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index 4b5f18e7bb..74f4750b13 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -1485,5 +1485,15 @@ class TestEnv < Test::Unit::TestCase ensure ENV["test"] = test end + + def test_utf8_empty + key = "VAR\u{e5 e1 e2 e4 e3 101 3042}" + ENV[key] = "x" + assert_equal "x", ENV[key] + ENV[key] = "" + assert_equal "", ENV[key] + ENV[key] = nil + assert_nil ENV[key] + end end end |