summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-04 21:57:34 +0900
committergit <svn-admin@ruby-lang.org>2023-09-05 13:47:52 +0000
commite1713fa6a32070210322455d79ac4d3769aa6414 (patch)
treef36aed7f6a213aeb5869d7f7b5f0a71d90446cad
parent6110f415cd761fbfa3b6215b47dc81640032aa55 (diff)
[ruby/yarp] Read template in UTF-8
https://github.com/ruby/yarp/commit/864b4ce99f
-rwxr-xr-xyarp/templates/template.rb20
1 files changed, 5 insertions, 15 deletions
diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb
index 6534205004..c661dd04e7 100755
--- a/yarp/templates/template.rb
+++ b/yarp/templates/template.rb
@@ -304,21 +304,11 @@ module YARP
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