diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-04 21:57:34 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-09-05 13:47:52 +0000 |
| commit | e1713fa6a32070210322455d79ac4d3769aa6414 (patch) | |
| tree | f36aed7f6a213aeb5869d7f7b5f0a71d90446cad | |
| parent | 6110f415cd761fbfa3b6215b47dc81640032aa55 (diff) | |
[ruby/yarp] Read template in UTF-8
https://github.com/ruby/yarp/commit/864b4ce99f
| -rwxr-xr-x | yarp/templates/template.rb | 20 |
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 |
