public
Created

  • Download Gist
fix_env_encoding.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
diff --git a/hash.c b/hash.c
index 06d0ce9..148f802 100644
--- a/hash.c
+++ b/hash.c
@@ -2110,7 +2110,7 @@ static VALUE
env_str_new(const char *ptr, long len)
{
#ifdef _WIN32
- VALUE str = rb_str_conv_enc(rb_str_new(ptr, len), rb_utf8_encoding(), rb_locale_encoding());
+ VALUE str = rb_str_conv_enc(rb_filesystem_str_new(ptr, len), NULL, rb_locale_encoding());
#else
VALUE str = rb_locale_str_new(ptr, len);
#endif
@@ -2192,11 +2192,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;
@@ -2247,11 +2243,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_str_new2(env);
}
diff --git a/win32/win32.c b/win32/win32.c
index 7eaf1fc..27964a7 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4281,7 +4281,7 @@ rb_w32_ugetenv(const char *name)
}
for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1)
wlen += lstrlenW(wenv) + 1;
- uenvarea = wstr_to_mbstr(CP_UTF8, wenvarea, wlen, NULL);
+ uenvarea = wstr_to_mbstr(filecp(), wenvarea, wlen, NULL);
FreeEnvironmentStringsW(wenvarea);
if (!uenvarea)
return NULL;

Win7 Ultimate 32bit

C:\Jenkins\workspace\ruby-trunk-svn>svn log -l 1
------------------------------------------------------------------------
r37127 | nobu | 2012-10-09 10:18:05 -0400 (Tue, 09 Oct 2012) | 5 lines

C:\projects\rubyinstaller-git>chcp 437
Active code page: 437

sh-3.1$ gcc --version
gcc.exe (rubenvb-4.7.2-release) 4.7.2

sh-3.1$ make test-all
...
[ 7332/11380] TestProcess#test_execopts_gid = 0.00 s
 41) Error:
test_execopts_gid(TestProcess):
NotImplementedError: groups() function is unimplemented on this machine
    c:/Jenkins/workspace/ruby-trunk-svn/test/ruby/test_process.rb:1506:in `groups'
    c:/Jenkins/workspace/ruby-trunk-svn/test/ruby/test_process.rb:1506:in `test_execopts_gid'
...
Finished tests in 606.269987s, 18.7705 tests/s, 4269.4427 assertions/s.
11380 tests, 2588435 assertions, 0 failures, 1 errors, 82 skips

ruby -v: ruby 2.0.0dev (2012-10-09 trunk 37127) [i386-mingw32]
make: *** [yes-test-all] Error 1

sh-3.1$ make test
...
test succeeded
PASS all 949 tests



C:\projects\rubyinstaller-git>chcp 1252
Active code page: 1252

sh-3.1$ make test-all
...
[ 7332/11380] TestProcess#test_execopts_gid = 0.00 s
 41) Error:
test_execopts_gid(TestProcess):
NotImplementedError: groups() function is unimplemented on this machine
    c:/Jenkins/workspace/ruby-trunk-svn/test/ruby/test_process.rb:1506:in `groups'
    c:/Jenkins/workspace/ruby-trunk-svn/test/ruby/test_process.rb:1506:in `test_execopts_gid'
...
Finished tests in 586.033631s, 19.4187 tests/s, 4445.4343 assertions/s.
11380 tests, 2605174 assertions, 0 failures, 1 errors, 82 skips


ruby -v: ruby 2.0.0dev (2012-10-09 trunk 37127) [i386-mingw32]
make: *** [yes-test-all] Error 1

sh-3.1$ make test
...
test succeeded
PASS all 949 tests

Win7 Ultimate 32bit - TestWEBrickCGI#test_cgi test w/codepages 437, 1252, 65001

C:\Jenkins\workspace>chcp
Active code page: 1252

C:\Jenkins\workspace>ruby -I ruby-trunk-svn\test\webrick ruby-trunk-svn\test\webrick\test_cgi.rb
Run options:

# Running tests:

Finished tests in 3.688211s, 1.0845 tests/s, 7.8629 assertions/s.
4 tests, 29 assertions, 0 failures, 0 errors, 0 skips

ruby -v: ruby 2.0.0dev (2012-10-09 trunk 37127) [i386-mingw32]


C:\Jenkins\workspace>chcp 437
Active code page: 437

C:\Jenkins\workspace>ruby -I ruby-trunk-svn\test\webrick ruby-trunk-svn\test\webrick\test_cgi.rb
Run options:

# Running tests:

[4/4] TestWEBrickCGI#test_cgi = 1.22 s
  1) Failure:
test_cgi(TestWEBrickCGI) [ruby-trunk-svn/test/webrick/test_cgi.rb:41]:
webrick log start:
  [2012-10-10 20:42:33] INFO  WEBrick 1.3.1
  [2012-10-10 20:42:33] INFO  ruby 2.0.0 (2012-10-09) [i386-mingw32]
  [2012-10-10 20:42:33] INFO  WEBrick::HTTPServer#start: pid=1620 port=50961

webrick log end.
"/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2" expected but was
"/\xC2\xA4\xC3\x9B\xC2\xA4\xC2\xB2/\xC2\xA4\xC3\x9B\xC2\xA4\xC2\xB2".

Finished tests in 1.578090s, 2.5347 tests/s, 11.4062 assertions/s.
4 tests, 18 assertions, 1 failures, 0 errors, 0 skips

ruby -v: ruby 2.0.0dev (2012-10-09 trunk 37127) [i386-mingw32]


C:\Jenkins\workspace>chcp 65001
Active code page: 65001

C:\Jenkins\workspace>ruby -I ruby-trunk-svn\test\webrick ruby-trunk-svn\test\webrick\test_cgi.rb
Run options:

# Running tests:

[4/4] TestWEBrickCGI#test_cgi = 1.21 s
  1) Failure:
test_cgi(TestWEBrickCGI) [ruby-trunk-svn/test/webrick/test_cgi.rb:41]:
webrick log start:
  [2012-10-10 20:42:42] INFO  WEBrick 1.3.1
  [2012-10-10 20:42:42] INFO  ruby 2.0.0 (2012-10-09) [i386-mingw32]
  [2012-10-10 20:42:42] INFO  WEBrick::HTTPServer#start: pid=1516 port=50972

webrick log end.
"/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2" expected but was
"/\xC2\xA4\xC3\x9B\xC2\xA4\xC2\xB2/\xC2\xA4\xC3\x9B\xC2\xA4\xC2\xB2".

Finished tests in 1.592092s, 2.5124 tests/s, 11.3059 assertions/s.
4 tests, 18 assertions, 1 failures, 0 errors, 0 skips

ruby -v: ruby 2.0.0dev (2012-10-09 trunk 37127) [i386-mingw32]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.