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 #2

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Status changed from Open to Closed

Applied in changeset git|cd5cafa4a380e2459862b6e99ff0c381362ef1be.


Respect the encoding of the source [Bug #18827]

Do not override the input string encoding at the time of preparation,
the source encoding is not determined from the input yet.

Updated by nagachika (Tomoyuki Chikanaga) over 1 year ago

  • Backport changed from 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE

ruby_3_1 8c99882dad0b6fedbd656889829a3780366bd8b6 merged revision(s) cd5cafa4a380e2459862b6e99ff0c381362ef1be.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0