Issue #10114 has been updated by Usaku NAKAMURA.

Backport changed from 2.0.0: REQUIRED, 2.1: DONE to 2.0.0: DONE, 2.1: DONE

backported into `ruby_2_0_0` at r47402.

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

* Author: Kevin de Berk
* Status: Closed
* 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: DONE, 2.1: DONE
----------------------------------------
~~~ruby
#!/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.







-- 
https://bugs.ruby-lang.org/