Project

General

Profile

Actions

Bug #20992

closed

`eval(ascii_encoded_code)` raises EncodingError when multibyte local variable exists

Bug #20992: `eval(ascii_encoded_code)` raises EncodingError when multibyte local variable exists

Added by tompng (tomoya ishida) 10 months ago. Updated 8 months ago.

Status:
Closed
Assignee:
Target version:
-
ruby -v:
ruby 3.5.0dev (2024-12-28T09:40:37Z master e4ec2128ae) +YJIT +MN +PRISM [arm64-darwin22]
[ruby-core:120443]

Description

#coding: utf-8
α=1
eval '1+2'.encode('ascii')
$ ruby file.rb
file.rb:3:in 'Kernel#eval': invalid symbol in encoding US-ASCII :"\xCE\xB1" (EncodingError)
	from file.rb:3:in '<main>'

Running the file below with LANG=C ruby file.rb will make IRB unresponsive

#coding: utf-8
α=1
binding.irb
$ LANG=C ruby file.rb
From: file.rb @ line 3 :

    1: #coding: utf-8
    2: α=1
 => 3: binding.irb
irb(main):001> 1
<internal:kernel>:168:in 'Kernel#loop': invalid symbol in encoding US-ASCII :"\xCE\xB1" (EncodingError)
	from <internal:prelude>:5:in 'Binding#irb'
	from file.rb:3:in '<main>'
irb(main):002> 

Updated by nobu (Nobuyoshi Nakada) 10 months ago Actions #1 [ruby-core:120444]

  • Assignee set to prism
  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED, 3.4: REQUIRED

Updated by nobu (Nobuyoshi Nakada) 10 months ago Actions #2

  • Status changed from Open to Closed

Applied in changeset git|5fec9308320e8b377681ef19b0cd46d53f94e8ac.


[Bug #20992] Test for local variable name encodings

Updated by nobu (Nobuyoshi Nakada) 10 months ago Actions #3

  • Status changed from Closed to Open

Updated by kddnewton (Kevin Newton) 10 months ago Actions #4

  • Status changed from Open to Closed

Applied in changeset git|1a06bee027d5c5b65ed0aaee76ee0040554d4efd.


Do not intern invalid symbols in eval parse

When the inner code cannot represent the name of the locals in the
outer code, do not bother putting them into the constant pool as
they will not be referenced.

Fixes [Bug #20992]

Co-authored-by: Nobuyoshi Nakada

Updated by k0kubun (Takashi Kokubun) 8 months ago Actions #5 [ruby-core:121008]

  • Backport changed from 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED, 3.4: REQUIRED to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED, 3.4: DONE
Actions

Also available in: PDF Atom