Forum: Ruby-core [Open] syntax error raised from instance_eval has unexpected encoding

7a0da602ecf562bfe0e06ff32575f31b?d=identicon&s=25 unknown (Guest)
on 2014-08-06 13:51
(Received via mailing list)
Issue #10114 has been reported by Kevin de Berk.

----------------------------------------
Bug #10114: syntax error raised from instance_eval has unexpected
encoding
https://bugs.ruby-lang.org/issues/10114

* Author: Kevin de Berk
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
* ruby -v: 2.0.0, 2.1.1, 2.1.2 are affected. 1.9.3 is not
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
~~~
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

code = 'def n "∈"; end'
puts "code.encoding: #{code.encoding} #{code.valid_encoding?}"

begin
  instance_eval(code)
rescue SyntaxError => error
  puts "error.message.encoding: #{error.message.encoding}
#{error.message.valid_encoding?}"
end
~~~

Outputs the following:
~~~
code.encoding: UTF-8 true
error.message.encoding: ASCII-8BIT true
~~~

but I expect error.message.encoding to be UTF-8.
This topic is locked and can not be replied to.