diff --git a/app/views/commits/_commit.html.haml b/app/views/commits/_commit.html.haml index a579cca96bba1079e6ee85fafd0e46be48854617..f52dbcfe723c6ef94f65f3fd86b18368eb7b9064 100644 --- a/app/views/commits/_commit.html.haml +++ b/app/views/commits/_commit.html.haml @@ -8,7 +8,7 @@ %strong.cgray= commit.author_name – = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16 - %span.row_title= truncate(commit.safe_message, :length => 50) rescue "--broken encoding" + %span.row_title= truncate(commit.safe_message, :length => 50) %span.right.cgray = time_ago_in_words(commit.committed_date) diff --git a/lib/gitlabhq/encode.rb b/lib/gitlabhq/encode.rb index e0e52f0a2a75710d82c653d3b99d9ee7e915cea7..780d839f420df01ad97e344ab656a6ccb3d48697 100644 --- a/lib/gitlabhq/encode.rb +++ b/lib/gitlabhq/encode.rb @@ -8,16 +8,19 @@ module Gitlabhq def utf8 message return nil unless message - encoding = detect_encoding(message) - if encoding + detect = CharlockHolmes::EncodingDetector.detect(message) rescue {} + + # It's better to default to UTF-8 as sometimes it's wrongly detected as another charset + if detect[:encoding] && detect[:confidence] == 100 CharlockHolmes::Converter.convert(message, encoding, 'UTF-8') else message end.force_encoding("utf-8") + # Prevent app from crash cause of # encoding errors rescue - "" + "--broken encoding: #{encoding}" end def detect_encoding message