Created
May 23, 2013 22:07
-
-
Save bri3d/5639849 to your computer and use it in GitHub Desktop.
Encoding getting lost through Symbol conversion in send (JRuby 1.7.x)
This file contains hidden or 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
# encoding: utf-8 | |
nyay = "ñ" | |
puts "Source string's encoding is #{nyay.encoding}" | |
class TestDispatch | |
def method_missing(name, *args) | |
puts "Sent name is a #{name.class.inspect} with encoding #{name.encoding}" | |
puts "Sent name as a string is #{name}" | |
end | |
end | |
t = TestDispatch.new | |
puts "Sending source string as string" | |
t.send(nyay) | |
puts "Sending source string as symbol" | |
t.send(nyay.to_sym) | |
=begin | |
JRuby 1.7.4, -Dfile.encoding=UTF8 | |
Oracle JDK7u15, 64-bit server | |
Locale en_US.UTF-8; reproduce on OSX and Ubuntu. | |
Output: | |
Source string's encoding is UTF-8 | |
Sending source string as string | |
Sent name is a Symbol with encoding US-ASCII | |
Sent name as a string is ? | |
Sending source string as symbol | |
Sent name is a Symbol with encoding UTF-8 | |
Sent name as a string is ñ | |
Ruby 1.9.3, OSX (reference/desired result): | |
Source string's encoding is UTF-8 | |
Sending source string as string | |
Sent name is a Symbol with encoding UTF-8 | |
Sent name as a string is ñ | |
Sending source string as symbol | |
Sent name is a Symbol with encoding UTF-8 | |
Sent name as a string is ñ | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment