summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-04-05 01:51:49 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-04-05 01:51:49 +0300
commit80ddd2c09d9017f49976436982e2b9be5084fc4c (patch)
tree3cf3a314f0a753ab6ef8a4c9c0dbc1fc06076137 /config
parent3706a9744d7d2976f53f46e5e0197323fa0670b0 (diff)
downloadgitlab-ce-80ddd2c09d9017f49976436982e2b9be5084fc4c.tar.gz
Better encoding handling. Updated grit
Diffstat (limited to 'config')
-rw-r--r--config/initializers/gitlabhq/20_grit_ext.rb30
1 files changed, 26 insertions, 4 deletions
diff --git a/config/initializers/gitlabhq/20_grit_ext.rb b/config/initializers/gitlabhq/20_grit_ext.rb
index a8c97b10929..9d4b22687e0 100644
--- a/config/initializers/gitlabhq/20_grit_ext.rb
+++ b/config/initializers/gitlabhq/20_grit_ext.rb
@@ -17,13 +17,35 @@ Grit::GitRuby::Internal::RawObject.class_eval do
end
private
+
def transcoding(content)
content ||= ""
- detection = CharlockHolmes::EncodingDetector.detect(content)
- if hash = detection
- content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
+ hash = CharlockHolmes::EncodingDetector.detect(content)
+
+ if hash
+ return content if hash[:type] == :binary
+
+ if hash[:encoding] == "UTF-8"
+ content = if hash[:confidence] < 100
+ content
+ else
+ content.force_encoding("UTF-8")
+ end
+
+ return content
+ end
+
+ CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
+ else
+ content.force_encoding("UTF-8")
+ end
+ end
+
+ def z_binary?(string)
+ string.each_byte do |x|
+ x.nonzero? or return true
end
- content
+ false
end
end