]> source.dussan.org Git - redmine.git/commitdiff
scm: not use Iconv for log converting in Ruby 1.9 and fix tests fails in Ruby 1.9.
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 9 Apr 2011 05:41:12 +0000 (05:41 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 9 Apr 2011 05:41:12 +0000 (05:41 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5367 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/changeset.rb
test/unit/changeset_test.rb

index 59b2302ac8a09db550ea5fa9f508a1263486a172..7039d99057d6f24348854ac8bd5ba70976f5d0fc 100644 (file)
@@ -245,21 +245,28 @@ class Changeset < ActiveRecord::Base
   private
 
   def self.to_utf8(str, encoding)
-    return str if str.blank?
-    unless encoding.blank? || encoding == 'UTF-8'
-      begin
-        str = Iconv.conv('UTF-8', encoding, str)
-      rescue Iconv::Failure
-        # do nothing here
-      end
-    end
+    return str if str.nil?
+    str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
+    return str if str.empty?
+    str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
     if str.respond_to?(:force_encoding)
-      str.force_encoding('UTF-8')
+      enc = encoding.blank? ? "UTF-8" : encoding
+      if enc != "UTF-8"
+        str.force_encoding(enc)
+        str = str.encode("UTF-8")
+      end
       if ! str.valid_encoding?
         str = str.encode("US-ASCII", :invalid => :replace,
               :undef => :replace, :replace => '?').encode("UTF-8")
       end
     else
+      unless encoding.blank? || encoding == 'UTF-8'
+        begin
+          str = Iconv.conv('UTF-8', encoding, str)
+        rescue Iconv::Failure
+          # do nothing here
+        end
+      end
       # removes invalid UTF8 sequences
       begin
         str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + '  ')[0..-3]
index 0e8c3c2b9041e9455bd85ab4617d5eb0fffa3d17..9000193d7eb88cb2c465e934d96d4708f37c6bf7 100644 (file)
@@ -269,9 +269,9 @@ class ChangesetTest < ActiveSupport::TestCase
   def test_comments_should_be_converted_all_latin1_to_utf8
       s1 = "\xC2\x80"
       s2 = "\xc3\x82\xc2\x80"
+      s4 = s2.dup
       if s1.respond_to?(:force_encoding)
         s3 = s1.dup
-        s4 = s2.dup
         s1.force_encoding('ASCII-8BIT')
         s2.force_encoding('ASCII-8BIT')
         s3.force_encoding('ISO-8859-1')
@@ -289,7 +289,7 @@ class ChangesetTest < ActiveSupport::TestCase
                         :scmid => '12345',
                         :comments => s1)
       assert( c.save )
-      assert_equal s2, c.comments
+      assert_equal s4, c.comments
   end
 
   def test_identifier