Commit 39def0dcbb17a3f5883d6cb1965f815b537e5890

Authored by Gabriel Mazetto
1 parent eb5749ed

Better fix for encoding problems on rendering of inline file visualizations like README files.

app/views/refs/_tree.html.haml
@@ -42,9 +42,9 @@ @@ -42,9 +42,9 @@
42 .readme 42 .readme
43 - if content.name =~ /\.(md|markdown)$/i 43 - if content.name =~ /\.(md|markdown)$/i
44 = preserve do 44 = preserve do
45 - = markdown(content.data.force_encoding('UTF-8')) 45 + = markdown(content.data.detect_encoding!)
46 - else 46 - else
47 - = simple_format(content.data.force_encoding('UTF-8')) 47 + = simple_format(content.data.detect_encoding!)
48 48
49 - if params[:path] 49 - if params[:path]
50 - history_path = tree_file_project_ref_path(@project, @ref, params[:path]) 50 - history_path = tree_file_project_ref_path(@project, @ref, params[:path])
app/views/refs/_tree_file.html.haml
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 #tree-readme-holder 13 #tree-readme-holder
14 .readme 14 .readme
15 = preserve do 15 = preserve do
16 - = markdown(file.data.force_encoding('UTF-8')) 16 + = markdown(file.data.detect_encoding!)
17 - else 17 - else
18 .view_file_content 18 .view_file_content
19 - unless file.empty? 19 - unless file.empty?
lib/gitlabhq/encode.rb
  1 +# Patch Strings to enable detect_encoding! on views
  2 +require 'charlock_holmes/string'
  3 +
1 module Gitlabhq 4 module Gitlabhq
2 module Encode 5 module Encode
3 extend self 6 extend self