]> source.dussan.org Git - redmine.git/commitdiff
scm: replace invalid utf-8 sequences instead of stripping in displaying repository...
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Tue, 12 Apr 2011 05:03:59 +0000 (05:03 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Tue, 12 Apr 2011 05:03:59 +0000 (05:03 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5427 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/repositories_helper.rb
test/unit/helpers/repository_helper_test.rb

index 36cd90fba75645422835fd76eef4671c6088489e..c873e1ce6d61fb8e68ec232a664ef6991c0e4821 100644 (file)
@@ -156,12 +156,18 @@ module RepositoriesHelper
               :undef => :replace, :replace => '?').encode("UTF-8")
       end
     else
-      # removes invalid UTF8 sequences
+      ic = Iconv.new('UTF-8', 'UTF-8')
+      txtar = ""
       begin
-        str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + '  ')[0..-3]
-      rescue Iconv::InvalidEncoding
-        # "UTF-8//IGNORE" is not supported on some OS
+        txtar += ic.iconv(str)
+      rescue Iconv::IllegalSequence
+        txtar += $!.success
+        str = '?' + $!.failed[1,$!.failed.length]
+        retry
+      rescue
+        txtar += $!.success
       end
+      str = txtar
     end
     str
   end
index 9532c3011efedd69941539db956bd79a09fe5342..a1c778e88d0f0d213f9b622a843e0060133381a3 100644 (file)
@@ -94,12 +94,10 @@ class RepositoryHelperTest < HelperTestCase
       s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
       str = to_utf8(s1)
       if str.respond_to?(:force_encoding)
-        assert_equal "Texte encod? en ISO-8859-1.", str
         assert str.valid_encoding?
         assert_equal "UTF-8", str.encoding.to_s
-      else
-        assert_equal "Texte encod en ISO-8859-1.", str
       end
+      assert_equal "Texte encod? en ISO-8859-1.", str
     end
   end
 end