Commit 80ddd2c09d9017f49976436982e2b9be5084fc4c
1 parent
3706a974
Exists in
master
and in
4 other branches
Better encoding handling. Updated grit
Showing
3 changed files
with
29 additions
and
6 deletions
Show diff stats
Gemfile.lock
... | ... | @@ -14,7 +14,7 @@ GIT |
14 | 14 | |
15 | 15 | GIT |
16 | 16 | remote: https://github.com/gitlabhq/grit.git |
17 | - revision: ff015074ef35bd94cba943f9c0f98e161ab5851c | |
17 | + revision: 3fc864f3c637e06e2fa7a81f6b48a5df58a9bc5b | |
18 | 18 | specs: |
19 | 19 | grit (2.4.1) |
20 | 20 | diff-lcs (~> 1.1) |
... | ... | @@ -148,7 +148,7 @@ GEM |
148 | 148 | mime-types (~> 1.16) |
149 | 149 | treetop (~> 1.4.8) |
150 | 150 | method_source (0.7.0) |
151 | - mime-types (1.17.2) | |
151 | + mime-types (1.18) | |
152 | 152 | modularity (0.6.1) |
153 | 153 | multi_json (1.0.4) |
154 | 154 | multi_xml (0.4.1) | ... | ... |
app/controllers/commits_controller.rb
config/initializers/gitlabhq/20_grit_ext.rb
... | ... | @@ -17,13 +17,35 @@ Grit::GitRuby::Internal::RawObject.class_eval do |
17 | 17 | end |
18 | 18 | |
19 | 19 | private |
20 | + | |
20 | 21 | def transcoding(content) |
21 | 22 | content ||= "" |
22 | - detection = CharlockHolmes::EncodingDetector.detect(content) | |
23 | - if hash = detection | |
24 | - content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding] | |
23 | + hash = CharlockHolmes::EncodingDetector.detect(content) | |
24 | + | |
25 | + if hash | |
26 | + return content if hash[:type] == :binary | |
27 | + | |
28 | + if hash[:encoding] == "UTF-8" | |
29 | + content = if hash[:confidence] < 100 | |
30 | + content | |
31 | + else | |
32 | + content.force_encoding("UTF-8") | |
33 | + end | |
34 | + | |
35 | + return content | |
36 | + end | |
37 | + | |
38 | + CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding] | |
39 | + else | |
40 | + content.force_encoding("UTF-8") | |
41 | + end | |
42 | + end | |
43 | + | |
44 | + def z_binary?(string) | |
45 | + string.each_byte do |x| | |
46 | + x.nonzero? or return true | |
25 | 47 | end |
26 | - content | |
48 | + false | |
27 | 49 | end |
28 | 50 | end |
29 | 51 | ... | ... |