Project

General

Profile

Actions

Bug #18827

closed

`__ENCODING__` is not set to the source encoding when saving script lines

Added by nobu (Nobuyoshi Nakada) over 2 years ago. Updated over 1 year ago.

Status:
Closed
Target version:
-
[ruby-core:108886]

Description

__ENCODING__ should respect the encoding of the given source code.

$ ruby -Ke -e 'p __ENCODING__'
#<Encoding:EUC-JP>
p eval("__ENCODING__".encode("euc-jp")) #=> #<Encoding:EUC-JP>

But it is ignored when SCRIPT_LINES__ is set.

$ cat script_lines.rb
SCRIPT_LINES__ = {}

$ ruby -r./script_lines.rb -Ke -e 'p __ENCODING__'
#<Encoding:UTF-8>

Also similar when keep_script_lines is true.

pp RubyVM::AbstractSyntaxTree.parse("__ENCODING__".encode("euc-jp"), keep_script_lines: true)
#=> (SCOPE@1:0-1:12 tbl: [] args: nil body: (LIT@1:0-1:12 #<Encoding:UTF-8>))
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0