diff options
author | Lars Kanis <[email protected]> | 2023-10-27 13:50:07 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-09-24 14:06:51 +0900 |
commit | acf28e835fc649c2a8597ef6244af5a8f61fa24a (patch) | |
tree | fc9bc3cad5aa2089f025430462a288843b0a01a7 | |
parent | 7627a95e414cec5753bae514fd5490777d9afd7f (diff) |
Windows: Use Unicode aware WinAPI function for ENV[]=
This only makes a difference when setting an empty value to a Unicode key.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7034
-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 |