Skip to content

Commit

Permalink
[ruby/yarp] Read template in UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Sep 5, 2023
1 parent 6110f41 commit e1713fa
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions yarp/templates/template.rb
Expand Up @@ -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

Expand Down

0 comments on commit e1713fa

Please sign in to comment.