Project

General

Profile

Feature #12650 » 0001-Always-use-UTF-8-encoded-environment-on-Windows.patch

davispuh (Dāvis Mosāns), 08/03/2016 12:51 AM

View differences:

hash.c
2896 2896
#undef environ
2897 2897
#define environ my_environ
2898 2898
#undef getenv
2899
static inline char *
2900
w32_getenv(const char *name)
2901
{
2902
    static int binary = -1;
2903
    static int locale = -1;
2904
    if (binary < 0) {
2905
	binary = rb_ascii8bit_encindex();
2906
	locale = rb_locale_encindex();
2907
    }
2908
    return locale == binary ? rb_w32_getenv(name) : rb_w32_ugetenv(name);
2909
}
2910
#define getenv(n) w32_getenv(n)
2899
#define getenv(n) rb_w32_ugetenv(n)
2911 2900
#elif defined(__APPLE__)
2912 2901
#undef environ
2913 2902
#define environ (*_NSGetEnviron())
......
2926 2915
#define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
2927 2916
#endif
2928 2917

  
2929
#ifdef _WIN32
2930
static VALUE
2931
env_str_transcode(VALUE str, rb_encoding *enc)
2932
{
2933
    return rb_str_conv_enc_opts(str, NULL, enc,
2934
				ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE, Qnil);
2935
}
2936
#endif
2937

  
2938 2918
static VALUE
2939 2919
env_str_new(const char *ptr, long len)
2940 2920
{
2941 2921
#ifdef _WIN32
2942
    VALUE str = env_str_transcode(rb_utf8_str_new(ptr, len), rb_locale_encoding());
2922
    VALUE str = rb_utf8_str_new(ptr, len);
2943 2923
#else
2944 2924
    VALUE str = rb_locale_str_new(ptr, len);
2945 2925
#endif
......
2952 2932
env_path_str_new(const char *ptr)
2953 2933
{
2954 2934
#ifdef _WIN32
2955
    VALUE str = env_str_transcode(rb_utf8_str_new_cstr(ptr), rb_filesystem_encoding());
2935
    VALUE str = rb_utf8_str_new_cstr(ptr);
2956 2936
#else
2957 2937
    VALUE str = rb_filesystem_str_new_cstr(ptr);
2958 2938
#endif
include/ruby/win32.h
695 695
#define getcwd(b, s)		rb_w32_getcwd(b, s)
696 696

  
697 697
#undef getenv
698
#define getenv(n)		rb_w32_getenv(n)
698
#define getenv(n)		rb_w32_ugetenv(n)
699 699

  
700 700
#undef rename
701 701
#define rename(o, n)		rb_w32_rename(o, n)
test/ruby/test_env.rb
510 510
      end;
511 511
    end
512 512

  
513
    if Encoding.find("locale") == Encoding::UTF_8
514
      def test_utf8
515
        text = "testing \u{e5 e1 e2 e4 e3 101 3042}"
516
        test = ENV["test"]
517
        ENV["test"] = text
518
        assert_equal text, ENV["test"]
519
      ensure
520
        ENV["test"] = test
521
      end
513
    def test_utf8
514
      text = "testing \u{e5 e1 e2 e4 e3 101 3042}"
515
      test = ENV["test"]
516
      ENV["test"] = text
517
      assert_equal text, ENV["test"]
518
    ensure
519
      ENV["test"] = test
522 520
    end
523 521
  end
524 522
end
test/ruby/test_m17n.rb
1312 1312
  end
1313 1313

  
1314 1314
  def test_env
1315
    locale_encoding = Encoding.find("locale")
1315
    if RUBY_PLATFORM =~ /bccwin|mswin|mingw/
1316
      env_encoding = Encoding::UTF_8
1317
    else
1318
      env_encoding = Encoding.find("locale")
1319
    end
1316 1320
    ENV.each {|k, v|
1317
      assert_equal(locale_encoding, k.encoding, k)
1318
      assert_equal(locale_encoding, v.encoding, v)
1321
      assert_equal(env_encoding, k.encoding, k)
1322
      assert_equal(env_encoding, v.encoding, v)
1319 1323
    }
1320 1324
  end
1321 1325