[ruby-core:76105] [Ruby trunk Bug#8822] Incorrect encoding for ENV in Windows

From: ethan_j_brown@...
Date: 2016-06-22 16:06:58 UTC
List: ruby-core #76105
Issue #8822 has been updated by Ethan Brown.

Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)

I don't believe this is properly fixed.

I just left a comment at https://bugs.ruby-lang.org/issues/9715#note-5, and will leave the same comment here:

The expectation is that regardless of current locale / codepage, I should get UTF-8 strings when using `ENV` on Windows.  Here is a simple reproduction of the failure on `2.3.0`:


```
C:\Users\Administrator> $env:unicode = 'taskᚠᛇᚻ'
C:\Users\Administrator> dir Env:\unicode

Name                           Value
----                           -----
unicode                        taskᚠᛇᚻ


C:\Users\Administrator> ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x64-mingw32]
C:\Users\Administrator> chcp
Active code page: 437

C:\Users\Administrator> irb
irb(main):001:0> RUBY_VERSION
=> "2.3.0"
irb(main):002:0> Encoding.default_internal
=> nil
irb(main):003:0> Encoding.default_external
=> #<Encoding:IBM437>
irb(main):004:0> str = ENV['unicode']
=> "task???"
irb(main):005:0> str.encoding
=> #<Encoding:IBM437>
```

Again, when I access `ENV` on Windows, I should receive a UTF-8 string with the correct data, *not* a `IBM437` string.  The expected string in this case is:


```
irb(main):036:0> str2 = "task\u16A0\u16C7\u16BB"
=> "task\u16A0\u16C7\u16BB"
irb(main):037:0> str2.encoding
=> #<Encoding:UTF-8>
```


Note that some browsers, like Chrome on OSX, may fail to render the Rune characters correctly, but if you copy into a proper editor or use another browser you should see the characters fine.

----------------------------------------
Bug #8822: Incorrect encoding for ENV in Windows
https://bugs.ruby-lang.org/issues/8822#change-59311

* Author: Dāvis Mosāns
* Status: Closed
* Priority: Normal
* Assignee: cruby-windows
* ruby -v: ruby 2.0.0p247 (2013-06-27) [x64-mingw32]
* Backport: 
----------------------------------------
When reading `ENV` and if it contains non-ASCII - string won't have correct encoding.
In Ruby 2.0 we can force it to UTF8 (it doesn't matter what's windows encoding nor consoles) and it will be correct, but in Ruby 1.9 there's no way to correctly read it.

Writing non-ASCII string to ENV is not possible at all neither of versions.

Also Ruby1.9 fails to read ENV with name witch contains non-ASCII

Here's [test.rb script](https://gist.github.com/davispuh/6351158) (basically set environment variable outside of ruby and in ruby print it out)

Output on [Ruby2.0](https://gist.github.com/davispuh/6351163) and on [Ruby1.9](https://gist.github.com/davispuh/6351207)

Seems it wasn't properly fixed in #5570




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next