From 7272dfa3c6d4c3c8877eea2a66fe84c7904cafa5 Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 24 Mar 2014 10:16:56 -0700 Subject: fixed problems when default encoding is not utf8 --- lib/leap_cli/config/manager.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/leap_cli/config/manager.rb') diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 46d7686..b610d3b 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + require 'json/pure' if $ruby_version < [1,9] @@ -230,7 +232,7 @@ module LeapCli Dir.glob(pattern).each do |filename| obj = load_json(filename, object_class) if obj - name = File.basename(filename).sub(/\.json$/,'') + name = File.basename(filename).force_encoding('utf-8').sub(/\.json$/,'') obj['name'] ||= name results[name] = obj end @@ -252,7 +254,7 @@ module LeapCli # https://www.ietf.org/rfc/rfc4627.txt # buffer = StringIO.new - File.open(filename, "rb") do |f| + File.open(filename, "rb", :encoding => 'UTF-8') do |f| while (line = f.gets) next if line =~ /^\s*\/\// buffer << line -- cgit v1.2.3