From 7d8bec3f20112151d1a295e6825ec8f5f3e9fc32 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 6 Jun 2015 18:10:47 -0400 Subject: [PATCH] Always treat formula files as UTF-8 --- Library/Homebrew/formulary.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index b56d190a00..9ed79db07b 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -17,7 +17,8 @@ class Formulary def self.load_formula(name, path) mod = Module.new const_set("FormulaNamespace#{Digest::MD5.hexdigest(path.to_s)}", mod) - mod.module_eval(path.read, path) + contents = path.open("r") { |f| set_encoding(f).read } + mod.module_eval(contents, path) class_name = class_s(name) begin @@ -29,6 +30,16 @@ class Formulary end end + if IO.method_defined?(:set_encoding) + def self.set_encoding(io) + io.set_encoding(Encoding::UTF_8) + end + else + def self.set_encoding(io) + io + end + end + def self.class_s name class_name = name.capitalize class_name.gsub!(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase }