Created
May 23, 2012 12:12
-
-
Save djberg96/2774883 to your computer and use it in GitHub Desktop.
JRuby's Encoding.default_external is causing trouble
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:21 | |
Encoding.default_external # => IBM437 in MRI, Windows-1252 in JRuby | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment