summaryrefslogtreecommitdiff
path: root/lib/utils.rb
diff options
context:
space:
mode:
authorSaito <saitowu@gmail.com>2011-11-28 17:46:41 +0800
committerSaito <saitowu@gmail.com>2011-11-28 17:46:41 +0800
commit46cbe5418947ab58c919432b9013252ada6a3bc3 (patch)
tree1c2ae343e97d0fa93f7c8e1ded4ab64f04ce6233 /lib/utils.rb
parent75fa0632e67b2b91401673b0dd292db4103224c8 (diff)
downloadgitlab-ce-46cbe5418947ab58c919432b9013252ada6a3bc3.tar.gz
fix the issue on github #157.
directly force_encoding is wrong, must detect the file string's encoding. then force_encoding the string to it's encoding. last convert it to utf-8.
Diffstat (limited to 'lib/utils.rb')
-rw-r--r--lib/utils.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/utils.rb b/lib/utils.rb
index f43e2edd207..23f05f6f919 100644
--- a/lib/utils.rb
+++ b/lib/utils.rb
@@ -16,9 +16,20 @@ module Utils
end
end
+ module CharEncode
+ def encode(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)
+ end
+ end
+
module Colorize
+ include CharEncode
def colorize
- system_colorize(data, name)
+ system_colorize(encode(data), name)
end
def system_colorize(data, file_name)