Feature #12650 » 0001-Always-use-UTF-8-encoded-environment-on-Windows.patch
| hash.c | ||
|---|---|---|
|
#undef environ
|
||
|
#define environ my_environ
|
||
|
#undef getenv
|
||
|
static inline char *
|
||
|
w32_getenv(const char *name)
|
||
|
{
|
||
|
static int binary = -1;
|
||
|
static int locale = -1;
|
||
|
if (binary < 0) {
|
||
|
binary = rb_ascii8bit_encindex();
|
||
|
locale = rb_locale_encindex();
|
||
|
}
|
||
|
return locale == binary ? rb_w32_getenv(name) : rb_w32_ugetenv(name);
|
||
|
}
|
||
|
#define getenv(n) w32_getenv(n)
|
||
|
#define getenv(n) rb_w32_ugetenv(n)
|
||
|
#elif defined(__APPLE__)
|
||
|
#undef environ
|
||
|
#define environ (*_NSGetEnviron())
|
||
| ... | ... | |
|
#define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
|
||
|
#endif
|
||
|
#ifdef _WIN32
|
||
|
static VALUE
|
||
|
env_str_transcode(VALUE str, rb_encoding *enc)
|
||
|
{
|
||
|
return rb_str_conv_enc_opts(str, NULL, enc,
|
||
|
ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE, Qnil);
|
||
|
}
|
||
|
#endif
|
||
|
static VALUE
|
||
|
env_str_new(const char *ptr, long len)
|
||
|
{
|
||
|
#ifdef _WIN32
|
||
|
VALUE str = env_str_transcode(rb_utf8_str_new(ptr, len), rb_locale_encoding());
|
||
|
VALUE str = rb_utf8_str_new(ptr, len);
|
||
|
#else
|
||
|
VALUE str = rb_locale_str_new(ptr, len);
|
||
|
#endif
|
||
| ... | ... | |
|
env_path_str_new(const char *ptr)
|
||
|
{
|
||
|
#ifdef _WIN32
|
||
|
VALUE str = env_str_transcode(rb_utf8_str_new_cstr(ptr), rb_filesystem_encoding());
|
||
|
VALUE str = rb_utf8_str_new_cstr(ptr);
|
||
|
#else
|
||
|
VALUE str = rb_filesystem_str_new_cstr(ptr);
|
||
|
#endif
|
||
| include/ruby/win32.h | ||
|---|---|---|
|
#define getcwd(b, s) rb_w32_getcwd(b, s)
|
||
|
#undef getenv
|
||
|
#define getenv(n) rb_w32_getenv(n)
|
||
|
#define getenv(n) rb_w32_ugetenv(n)
|
||
|
#undef rename
|
||
|
#define rename(o, n) rb_w32_rename(o, n)
|
||
| test/ruby/test_env.rb | ||
|---|---|---|
|
end;
|
||
|
end
|
||
|
if Encoding.find("locale") == Encoding::UTF_8
|
||
|
def test_utf8
|
||
|
text = "testing \u{e5 e1 e2 e4 e3 101 3042}"
|
||
|
test = ENV["test"]
|
||
|
ENV["test"] = text
|
||
|
assert_equal text, ENV["test"]
|
||
|
ensure
|
||
|
ENV["test"] = test
|
||
|
end
|
||
|
def test_utf8
|
||
|
text = "testing \u{e5 e1 e2 e4 e3 101 3042}"
|
||
|
test = ENV["test"]
|
||
|
ENV["test"] = text
|
||
|
assert_equal text, ENV["test"]
|
||
|
ensure
|
||
|
ENV["test"] = test
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| test/ruby/test_m17n.rb | ||
|---|---|---|
|
end
|
||
|
def test_env
|
||
|
locale_encoding = Encoding.find("locale")
|
||
|
if RUBY_PLATFORM =~ /bccwin|mswin|mingw/
|
||
|
env_encoding = Encoding::UTF_8
|
||
|
else
|
||
|
env_encoding = Encoding.find("locale")
|
||
|
end
|
||
|
ENV.each {|k, v|
|
||
|
assert_equal(locale_encoding, k.encoding, k)
|
||
|
assert_equal(locale_encoding, v.encoding, v)
|
||
|
assert_equal(env_encoding, k.encoding, k)
|
||
|
assert_equal(env_encoding, v.encoding, v)
|
||
|
}
|
||
|
end
|
||