Fixed encoding problems with plain/text blobs being sent without charset.

This commit is contained in:
Gabriel Mazetto 2012-05-26 15:20:35 -03:00
parent cc8369144d
commit eb5749ed39
2 changed files with 19 additions and 4 deletions

View file

@ -5,9 +5,9 @@ module Gitlabhq
def utf8 message
return nil unless message
hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
if hash[:encoding]
CharlockHolmes::Converter.convert(message, hash[:encoding], 'UTF-8')
encoding = detect_encoding(message)
if encoding
CharlockHolmes::Converter.convert(message, encoding, 'UTF-8')
else
message
end.force_encoding("utf-8")
@ -16,5 +16,12 @@ module Gitlabhq
rescue
""
end
def detect_encoding message
return nil unless message
hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
return hash[:encoding] ? hash[:encoding] : nil
end
end
end