
Issue #18827 has been updated by nagachika (Tomoyuki Chikanaga). 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. ---------------------------------------- Bug #18827: `__ENCODING__` is not set to the source encoding when saving script lines https://bugs.ruby-lang.org/issues/18827#change-102545 * Author: nobu (Nobuyoshi Nakada) * Status: Closed * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * Backport: 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE ---------------------------------------- `__ENCODING__` should respect the encoding of the given source code. ```shell-session $ ruby -Ke -e 'p __ENCODING__' #<Encoding:EUC-JP> ``` ```ruby p eval("__ENCODING__".encode("euc-jp")) #=> #<Encoding:EUC-JP> ``` But it is ignored when `SCRIPT_LINES__` is set. ```shell-session $ 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. ```ruby 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>)) ``` -- https://bugs.ruby-lang.org/