From f615c877bcb36aa2e4bc399545376671b55f167e Mon Sep 17 00:00:00 2001 From: Saito Date: Tue, 13 Dec 2011 00:41:31 +0800 Subject: [PATCH] fix can not guess problem --- app/helpers/application_helper.rb | 1 + app/helpers/commits_helper.rb | 2 -- lib/utils.rb | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 47067083..ed065bc4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,6 @@ require 'digest/md5' module ApplicationHelper + include Utils::CharEncode def gravatar_icon(user_email) gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com" diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index ae782671..98ec9936 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -1,6 +1,4 @@ module CommitsHelper - include Utils::CharEncode - def old_line_number(line, i) end diff --git a/lib/utils.rb b/lib/utils.rb index 17c9dfe3..2de14761 100644 --- a/lib/utils.rb +++ b/lib/utils.rb @@ -18,13 +18,14 @@ module Utils module CharEncode def encode(string) + return '' unless string cd = CharDet.detect(string) if cd.confidence > 0.6 string.force_encoding(cd.encoding) end string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace) rescue - "Invalid code encoding" + "Invalid Encoding" end end