]> source.dussan.org Git - redmine.git/commitdiff
scm: to_utf8() in repositories_helper always returns UTF-8 in Ruby 1.9.
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 19 Mar 2011 05:46:25 +0000 (05:46 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 19 Mar 2011 05:46:25 +0000 (05:46 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5165 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 6776531a7d437afd842af0432b4932d4a21868f7..234a884b3edf9ba88a4db5ce40b1c2b2397a6071 100644 (file)
@@ -117,7 +117,16 @@ module RepositoriesHelper
   end
 
   def to_utf8(str)
-    return str if str.nil? 
+    return str if str.nil?
+    str = to_utf8_internal(str)
+    if str.respond_to?(:force_encoding)
+      str.force_encoding('UTF-8')
+    end
+    str
+  end
+
+  def to_utf8_internal(str)
+    return str if str.nil?
     if str.respond_to?(:force_encoding)
       str.force_encoding('ASCII-8BIT')
     end
@@ -136,6 +145,7 @@ module RepositoriesHelper
     end
     str = replace_invalid_utf8(str)
   end
+  private :to_utf8_internal
 
   def replace_invalid_utf8(str)
     if str.respond_to?(:force_encoding)
index c5e66055c95d23ed33fd04ff03e6c41091fe8273..42b087ce4c236d611f0e3420ed220c6de6d2139b 100644 (file)
@@ -69,5 +69,21 @@ class RepositoryHelperTest < HelperTestCase
     assert_equal "",  to_utf8("")
     assert_equal nil, to_utf8(nil)
   end
-end
 
+  def test_to_utf8_returns_ascii_as_utf8
+    s1 = "ASCII"
+    s2 = s1.dup
+    if s1.respond_to?(:force_encoding)
+      s1.force_encoding("UTF-8")
+      s2.force_encoding("ISO-8859-1")
+    end
+    str1 = to_utf8(s1)
+    str2 = to_utf8(s2)
+    assert_equal s1, str1
+    assert_equal s1, str2
+    if s1.respond_to?(:force_encoding)
+      assert_equal "UTF-8", str1.encoding.to_s
+      assert_equal "UTF-8", str2.encoding.to_s
+    end
+  end
+end