diff lib/redmine/codeset_util.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents cbb26bc654de
children
line wrap: on
line diff
--- a/lib/redmine/codeset_util.rb	Fri Jun 14 09:01:12 2013 +0100
+++ b/lib/redmine/codeset_util.rb	Fri Jun 14 09:02:21 2013 +0100
@@ -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)