Project

General

Profile

Actions

Bug #5570

closed

Encoding of environment variables on Windows

Added by now (Nikolai Weibull) about 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3dev (2011-09-13 revision 33263) [i386-mingw32]
Backport:
[ruby-core:40737]

Description

It seems that the filesystem encoding is forced upon environment variables. There is, however, no guarantee that this encoding is the correct one. Getenv() probably shouldn’t be used on Windows at all. Using _wgetenv instead should guarantee that the returned result is encoded properly and it can then be converted to the filesystem encoding.

Updated by ko1 (Koichi Sasada) almost 13 years ago

  • Assignee set to usa (Usaku NAKAMURA)

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Open to Rejected

Ruby uses AreFileApisANSI() ? GetACP() : GetOEMCP() on Windows, not environment variables.

Updated by now (Nikolai Weibull) almost 13 years ago

On Sun, Mar 11, 2012 at 15:36, Yui NARUSE wrote:

Issue #5570 has been updated by Yui NARUSE.

Status changed from Open to Rejected

Ruby uses AreFileApisANSI() ? GetACP() : GetOEMCP() on Windows, not environment variables.

The problem is with the encoding of the values of the environment
variables, not whether environment variables are used to determine the
encoding of file names or not.

Please re-open.

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Rejected to Assigned

Ah, you are saying "use Wide API".

Updated by luislavena (Luis Lavena) almost 13 years ago

Correct,

A example that reproduces the issue:

C:\Users\Luis>ruby -v
ruby 1.9.3p155 (2012-03-03 revision 34878) [i386-mingw32]

C:\Users\Luis>chcp
Active code page: 1252

C:\Users\Luis>SET FOO=fóñè

C:\Users\Luis>ruby -e "puts ENV['FOO']"
fóñè

C:\Users\Luis>chcp 65001
Active code page: 65001

C:\Users\Luis>ruby -e "puts ENV['FOO']"
f���

This also happens with environment variables used to construct users home directory "~" if they contain accented characters.

Updated by nobu (Nobuyoshi Nakada) almost 13 years ago

  • Status changed from Assigned to Feedback
  • Target version set to 2.0.0

Which codepage should be used there, ACP or OEMCP?

Updated by now (Nikolai Weibull) almost 13 years ago

On Sun, Mar 11, 2012 at 22:44, Nobuyoshi Nakada wrote:

Issue #5570 has been updated by Nobuyoshi Nakada.

Status changed from Assigned to Feedback
Target version set to 2.0.0

Which codepage should be used there, ACP or OEMCP?

I’m not sure that I understand what the question is referring to, but
the encoding of the value of environment variables should be the
filesystem encoding on Windows, just as it is on Unix. The only
difference is that _wgetenv should be used instead of getenv so that
the transcoding can be done reliably.

Updated by now (Nikolai Weibull) almost 13 years ago

On Thu, Mar 15, 2012 at 02:51, U.Nakamura wrote:

Hello,

In message "[ruby-core:43237] [ruby-trunk - Bug #5570][Feedback] Encoding of environment variables on Windows"
   on Mar.12,2012 06:44:04, wrote:

Which codepage should be used there, ACP or OEMCP?

maybe locale?

Huh? Again, this isn’t the issue.

Actions #9

Updated by usa (Usaku NAKAMURA) almost 13 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35030.
Nikolai, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • win32/win32.c, include/ruby/win32.h (rb_w32_ugetenv): new API to
    accept and to return UTF-8 strings.

  • win32/win32.c (rb_w32_getenv): follow above change.

  • win32/win32.c (rb_w32_get_environ): returns UTF-8 environment area.

  • hash.c (env_str_new, rb_f_getenv, env_fetch): follow above changes.
    [Bug #5570] [ruby-core:40737]

Updated by now (Nikolai Weibull) almost 13 years ago

On Thu, Mar 15, 2012 at 05:16, Nikolai Weibull wrote:

On Thu, Mar 15, 2012 at 02:51, U.Nakamura wrote:

Hello,

In message "[ruby-core:43237] [ruby-trunk - Bug #5570][Feedback] Encoding of environment variables on Windows"
   on Mar.12,2012 06:44:04, wrote:

Which codepage should be used there, ACP or OEMCP?

maybe locale?

Huh?  Again, this isn’t the issue.

This seems to have been resolved in 35030.

Thanks!

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0