When dispatching a string through send to method_missing, the string loses its encoding and becomes ASCII. However, it is not re-encoded and hence causes all sorts of undefined behavior down the road.
JRuby 1.7.3, java version "1.7.0_15"
Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
External and internal encodings are UTF-8 as well as JVM's file encoding.
here is a simple test case:
class TestDispatch
def method_missing(name, *args)
puts name.encoding
end
end
nyay = 'ñ'
puts nyay.encoding # => #<Encoding:UTF-8>
puts nyay.to_sym.encoding # => #<Encoding:UTF-8>
t = TestDispatch.new
t.send(nyay) # => US-ASCII, should be UTF-8
t.send(nyay.to_sym) # => UTF-8
additionally
class TestDispatch
def method_missing(name, *args)
puts name.encoding
name.to_s.bytes.map {|b| puts b }
end
end
t = TestDispatch.new
t.send('ñ') # => US-ASCII \n 241
Note that 241 is the Unicode decimal representation of ñ, and not real ASCII. So the string is not being re-encoded into ASCII but rather is losing its UTF-8 encoding.
When dispatching a string through send to method_missing, the string loses its encoding and becomes ASCII. However, it is not re-encoded and hence causes all sorts of undefined behavior down the road.
JRuby 1.7.3, java version "1.7.0_15"
Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
External and internal encodings are UTF-8 as well as JVM's file encoding.
here is a simple test case:
additionally
Note that 241 is the Unicode decimal representation of ñ, and not real ASCII. So the string is not being re-encoded into ASCII but rather is losing its UTF-8 encoding.