diff options
author | Saito <saitowu@gmail.com> | 2011-11-28 17:46:41 +0800 |
---|---|---|
committer | Saito <saitowu@gmail.com> | 2011-11-28 17:46:41 +0800 |
commit | 46cbe5418947ab58c919432b9013252ada6a3bc3 (patch) | |
tree | 1c2ae343e97d0fa93f7c8e1ded4ab64f04ce6233 /lib/utils.rb | |
parent | 75fa0632e67b2b91401673b0dd292db4103224c8 (diff) | |
download | gitlab-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.rb | 13 |
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) |