##// END OF EJS Templates
scm: fix repository helper unit test fails in Ruby 1.9 and non UTF-8 locale....
Toshi MARUYAMA -
r5038:4923ff76faea
parent child
Show More
@@ -117,16 +117,15 module RepositoriesHelper
117 117 end
118 118
119 119 def to_utf8(str)
120 return str if str.blank?
120 return str if str.nil?
121 if str.respond_to?(:force_encoding)
122 str.force_encoding('ASCII-8BIT')
123 end
124 return str if str.empty?
125 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
121 126 if str.respond_to?(:force_encoding)
122 127 str.force_encoding('UTF-8')
123 else
124 # TODO:
125 # Japanese Shift_JIS(CP932) is not compatible with ASCII.
126 # UTF-7 and Japanese ISO-2022-JP are 7bits clean.
127 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
128 128 end
129
130 129 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
131 130 @encodings.each do |encoding|
132 131 begin
@@ -24,7 +24,7 class RepositoryHelperTest < HelperTestCase
24 24 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
25 25 s1 = "Texte encod\xc3\xa9"
26 26 s2 = "Texte encod\xe9"
27 s3 = s2
27 s3 = s2.dup
28 28 if s1.respond_to?(:force_encoding)
29 29 s1.force_encoding("UTF-8")
30 30 s2.force_encoding("ASCII-8BIT")
@@ -39,7 +39,7 class RepositoryHelperTest < HelperTestCase
39 39 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
40 40 s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
41 41 s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
42 s3 = s2
42 s3 = s2.dup
43 43 if s1.respond_to?(:force_encoding)
44 44 s1.force_encoding("UTF-8")
45 45 s2.force_encoding("ASCII-8BIT")
@@ -54,7 +54,7 class RepositoryHelperTest < HelperTestCase
54 54 with_settings :repositories_encodings => 'ISO-8859-1' do
55 55 s1 = "\xc3\x82\xc2\x80"
56 56 s2 = "\xC2\x80"
57 s3 = s2
57 s3 = s2.dup
58 58 if s1.respond_to?(:force_encoding)
59 59 s1.force_encoding("UTF-8")
60 60 s2.force_encoding("ASCII-8BIT")
@@ -64,5 +64,10 class RepositoryHelperTest < HelperTestCase
64 64 assert_equal s1, to_utf8(s3)
65 65 end
66 66 end
67
68 def test_to_utf8_blank_string
69 assert_equal "", to_utf8("")
70 assert_equal nil, to_utf8(nil)
71 end
67 72 end
68 73
General Comments 0
You need to be logged in to leave comments. Login now