[前][次][番号順一覧][スレッド一覧]

ruby-changes:63651

From: Jeremy <ko1@a...>
Date: Thu, 19 Nov 2020 07:13:07 +0900 (JST)
Subject: [ruby-changes:63651] 4a5c42db88 (master): Make RubyVM::InstructionSequence.compile_file use same encoding as load

https://git.ruby-lang.org/ruby.git/commit/?id=4a5c42db88

From 4a5c42db88d30532bd4fbcdff89615ebf961d2a2 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Wed, 18 Nov 2020 11:39:59 -0800
Subject: Make RubyVM::InstructionSequence.compile_file use same encoding as
 load

This switches the internal function from rb_parser_compile_file_path
to rb_parser_load_file, which is the same internal method that
Kernel#load uses.

Fixes [Bug #17308]

diff --git a/iseq.c b/iseq.c
index af78269..4a67ee1 100644
--- a/iseq.c
+++ b/iseq.c
@@ -1303,7 +1303,7 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1303
 
     parser = rb_parser_new();
     rb_parser_set_context(parser, NULL, FALSE);
-    ast = rb_parser_compile_file_path(parser, file, f, NUM2INT(line));
+    ast = (rb_ast_t *)rb_parser_load_file(parser, file);
     if (!ast->body.root) exc = GET_EC()->errinfo;
 
     rb_io_close(f);
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 51e3fd0..3ec06b4 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -98,6 +98,22 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L98
     assert_include(RubyVM::InstructionSequence.of(obj.method(name)).disasm, name)
   end
 
+  def test_compile_file_encoding
+    Tempfile.create(%w"test_iseq .rb") do |f|
+      f.puts "{ '\u00de' => 'Th', '\u00df' => 'ss', '\u00e0' => 'a' }"
+      f.close
+
+      previous_external = Encoding.default_external
+      Encoding.default_external = Encoding::US_ASCII
+      begin
+        load f.path
+        RubyVM::InstructionSequence.compile_file(f.path)
+      ensure
+        Encoding.default_external = previous_external
+      end
+    end
+  end
+
   LINE_BEFORE_METHOD = __LINE__
   def method_test_line_trace
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]