From 39def0dcbb17a3f5883d6cb1965f815b537e5890 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Sat, 26 May 2012 15:22:47 -0300 Subject: [PATCH] Better fix for encoding problems on rendering of inline file visualizations like README files. --- app/views/refs/_tree.html.haml | 4 ++-- app/views/refs/_tree_file.html.haml | 2 +- lib/gitlabhq/encode.rb | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/refs/_tree.html.haml b/app/views/refs/_tree.html.haml index 137501eaf1..0d9d2d7541 100644 --- a/app/views/refs/_tree.html.haml +++ b/app/views/refs/_tree.html.haml @@ -42,9 +42,9 @@ .readme - if content.name =~ /\.(md|markdown)$/i = preserve do - = markdown(content.data.force_encoding('UTF-8')) + = markdown(content.data.detect_encoding!) - else - = simple_format(content.data.force_encoding('UTF-8')) + = simple_format(content.data.detect_encoding!) - if params[:path] - history_path = tree_file_project_ref_path(@project, @ref, params[:path]) diff --git a/app/views/refs/_tree_file.html.haml b/app/views/refs/_tree_file.html.haml index 3fcc37331e..608faaa83c 100644 --- a/app/views/refs/_tree_file.html.haml +++ b/app/views/refs/_tree_file.html.haml @@ -13,7 +13,7 @@ #tree-readme-holder .readme = preserve do - = markdown(file.data.force_encoding('UTF-8')) + = markdown(file.data.detect_encoding!) - else .view_file_content - unless file.empty? diff --git a/lib/gitlabhq/encode.rb b/lib/gitlabhq/encode.rb index 6069f4f90a..e0e52f0a2a 100644 --- a/lib/gitlabhq/encode.rb +++ b/lib/gitlabhq/encode.rb @@ -1,3 +1,6 @@ +# Patch Strings to enable detect_encoding! on views +require 'charlock_holmes/string' + module Gitlabhq module Encode extend self