Project

General

Profile

Bug #10114

syntax error raised from instance_eval has unexpected encoding

Added by kdeberk (Kevin de Berk) over 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.0.0, 2.1.1, 2.1.2 are affected. 1.9.3 is not
[ruby-core:64228]

Description

#!/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.

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Description updated (diff)
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r47090.


parse.y: preserve encoding

  • parse.y (parser_yyerror): preserve source code encoding in syntax error messages. [ruby-core:64228] [Bug #10114]

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

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

Backported into ruby_2_1 branch at r47267.

Updated by usa (Usaku NAKAMURA) about 6 years ago

  • 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.

Also available in: Atom PDF