]> source.dussan.org Git - redmine.git/commitdiff
Fixes utf8 conversions with ruby1.9.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 1 Jan 2011 19:12:35 +0000 (19:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 1 Jan 2011 19:12:35 +0000 (19:12 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4605 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/attachments_helper.rb
app/helpers/repositories_helper.rb
app/models/changeset.rb

index 50b44890f2499f4fa5d226b222c93f0bab8c5ccd..367976515cde3abeddf85950cfcedc2b900a9f1d 100644 (file)
@@ -29,7 +29,13 @@ module AttachmentsHelper
   end
   
   def to_utf8(str)
-    return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+    if str.respond_to?(:force_encoding)
+      str.force_encoding('UTF-8')
+      return str if str.valid_encoding?
+    else
+      return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+    end
+    
     begin
       Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + '  ')[0..-3]
     rescue Iconv::InvalidEncoding
index 95962873541d1d0d7fa57fe42801699a3c1d5665..19a86e00c8c4523ebd989aec3d3dc6d03d1690e9 100644 (file)
@@ -113,7 +113,13 @@ module RepositoriesHelper
   end
   
   def to_utf8(str)
-    return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+    if str.respond_to?(:force_encoding)
+      str.force_encoding('UTF-8')
+      return str if str.valid_encoding?
+    else
+      return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+    end
+    
     @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
     @encodings.each do |encoding|
       begin
index 804719481e210d235f3f146f03e089bb953b7956..ca4daace825017e584e7e6606c8ac5816a514f29 100644 (file)
@@ -227,7 +227,13 @@ class Changeset < ActiveRecord::Base
   end
 
   def self.to_utf8(str)
-    return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+    if str.respond_to?(:force_encoding)
+      str.force_encoding('UTF-8')
+      return str if str.valid_encoding?
+    else
+      return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+    end
+
     encoding = Setting.commit_logs_encoding.to_s.strip
     unless encoding.blank? || encoding == 'UTF-8'
       begin