Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.7
-
Fix Version/s: JRuby 1.7.0.pre2
-
Component/s: None
-
Labels:None
-
Environment:jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (Java HotSpot(TM) Client VM 1.6.0_23) [Windows 7-x86-java]
-
Number of attachments :
Description
Hi,
I'm seeing different default external encodings between JRuby and MRI,
which is causing me a bit of grief trying to convert some win32 stuff
to FFI.
ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
C:\Users\djberge\Repositories\win32-dir>irb
irb(main):001:0> Encoding.default_external
=> #<Encoding:IBM437>
jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (Java
HotSpot(TM) Client VM 1.6.0_23) [Windows 7-x86-java]
C:\Users\djberge\Repositories\win32-dir>jirb
irb(main):001:0> Encoding.default_external
=> #<Encoding:Windows-1252>
It seems MRI is using the console encoding by default for strings,
while JRuby is using the system encoding. Which is correct?
Park Heesob was kind enough to link me to a couple of related articles:
http://en.wikipedia.org/wiki/Code_page
http://blogs.msdn.com/b/michkap/archive/2005/02/08/369197.aspx
Regards,
Dan
Here's an example of some problematic code being caused by this (I think):
require 'ffi' class Windows extend FFI::Library ffi_lib :shell32 attach_function :SHGetFolderPath, :SHGetFolderPathW, [:ulong, :int, :ulong, :ulong, :buffer_out], :ulong def self.folder buf = 0.chr * 1024 buf.encode!('UTF-16LE') if SHGetFolderPath(0, 47, 0, 1, buf) != 0 raise SystemCallError, FFI.errno, "SHGetFolderPath" end buf.encode(Encoding.default_external).strip end end p Windows.folder # MRI "C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Administrative Tools" # JRuby Encoding::UndefinedConversionError: Input length = 1 encode at org/jruby/RubyString.java:7446 folder at folders.rb:17 (root) at folders.rb:21With 1.6.7.2 in --1.9 mode I was getting an InvalidByteSequence error, btw.