[ruby-core:66210] [ruby-trunk - Bug #10493] Wrong encoding for Etc.getlogin in Windows

From: davispuh@...
Date: 2014-11-11 16:27:08 UTC
List: ruby-core #66210
Issue #10493 has been updated by Dāvis Mosāns.


Thanks, that was surprisingly easy. Only trunk didn't build so I compiled from ruby_2_1 branch and cherry-picked r48360, r48364
Now I can confirm that patch works.

```ruby
name = Etc.getlogin
puts name.inspect   # "D\u0101vis"
puts name.encoding  # UTF-8
```


But looks like encoding for string outputting have been broken somewhere (I hope it's fixed in some commits not yet merged in this branch)

```ruby
puts "\u0101"
=> ā   # on released Ruby 2.1.4p265
=> Ä?  # on 2.1.5p272, I just compiled from ruby_2_1 branch
```

It used to be that when outputting string it's encoded to `Encoding.default_external`, but that's not the case for this.

----------------------------------------
Bug #10493: Wrong encoding for Etc.getlogin in Windows
https://bugs.ruby-lang.org/issues/10493#change-49905

* Author: Dāvis Mosāns
* Status: Closed
* Priority: Normal
* Assignee: 
* Category: ext
* Target version: current: 2.2.0
* ruby -v: ruby 2.1.4p265 (2014-10-27 revision 48166) [x64-mingw32]
* Backport: 2.0.0: REQUIRED, 2.1: REQUIRED
----------------------------------------

~~~ruby
name = Etc.getlogin # I've Windows username "Dāvis"
puts name           # D�vis
puts name.inspect   # "D\xE2vis"
puts name.encoding  # ASCII-8BIT
name.force_encoding('Windows-1257')
puts name           # Dāvis
~~~

As you can see \xE2 isn't "ā" in ASCII, but it is for Windws-1257 encoding.






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

In This Thread

Prev Next