Mercurial > hg > soundsoftware-site
diff lib/redmine/codeset_util.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | cbb26bc654de |
children |
line wrap: on
line diff
--- a/lib/redmine/codeset_util.rb Fri Jun 14 09:05:06 2013 +0100 +++ b/lib/redmine/codeset_util.rb Tue Jan 14 14:37:42 2014 +0000 @@ -1,4 +1,6 @@ -require 'iconv' +if RUBY_VERSION < '1.9' + require 'iconv' +end module Redmine module CodesetUtil @@ -100,10 +102,20 @@ end encodings = Setting.repositories_encodings.split(',').collect(&:strip) encodings.each do |encoding| - begin - return Iconv.conv('UTF-8', encoding, str) - rescue Iconv::Failure - # do nothing here and try the next encoding + if str.respond_to?(:force_encoding) + begin + str.force_encoding(encoding) + utf8 = str.encode('UTF-8') + return utf8 if utf8.valid_encoding? + rescue + # do nothing here and try the next encoding + end + else + begin + return Iconv.conv('UTF-8', encoding, str) + rescue Iconv::Failure + # do nothing here and try the next encoding + end end end str = self.replace_invalid_utf8(str)