From e1713fa6a32070210322455d79ac4d3769aa6414 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 4 Sep 2023 21:57:34 +0900 Subject: [PATCH] [ruby/yarp] Read template in UTF-8 https://github.com/ruby/yarp/commit/864b4ce99f --- yarp/templates/template.rb | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index 6534205004ffa1..c661dd04e73f44 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -304,21 +304,11 @@ def template(name, write_to: nil) private def read_template(filepath) - previous_verbosity = $VERBOSE - previous_default_external = Encoding.default_external - $VERBOSE = nil - - begin - Encoding.default_external = Encoding::UTF_8 - - if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ - ERB.new(File.read(filepath), trim_mode: "-") - else - ERB.new(File.read(filepath), nil, "-") - end - ensure - Encoding.default_external = previous_default_external - $VERBOSE = previous_verbosity + template = File.read(filepath, encoding: Encoding::UTF_8) + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ + ERB.new(template, trim_mode: "-") + else + ERB.new(template, nil, "-") end end