##// END OF EJS Templates
scm: replace invalid utf-8 sequences instead of stripping in displaying repository contents on Ruby 1.8....
Toshi MARUYAMA -
r5307:bb48d96d3037
parent child
Show More
@@ -156,12 +156,18 module RepositoriesHelper
156 :undef => :replace, :replace => '?').encode("UTF-8")
156 :undef => :replace, :replace => '?').encode("UTF-8")
157 end
157 end
158 else
158 else
159 # removes invalid UTF8 sequences
159 ic = Iconv.new('UTF-8', 'UTF-8')
160 txtar = ""
160 begin
161 begin
161 str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
162 txtar += ic.iconv(str)
162 rescue Iconv::InvalidEncoding
163 rescue Iconv::IllegalSequence
163 # "UTF-8//IGNORE" is not supported on some OS
164 txtar += $!.success
165 str = '?' + $!.failed[1,$!.failed.length]
166 retry
167 rescue
168 txtar += $!.success
164 end
169 end
170 str = txtar
165 end
171 end
166 str
172 str
167 end
173 end
@@ -94,12 +94,10 class RepositoryHelperTest < HelperTestCase
94 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
94 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
95 str = to_utf8(s1)
95 str = to_utf8(s1)
96 if str.respond_to?(:force_encoding)
96 if str.respond_to?(:force_encoding)
97 assert_equal "Texte encod? en ISO-8859-1.", str
98 assert str.valid_encoding?
97 assert str.valid_encoding?
99 assert_equal "UTF-8", str.encoding.to_s
98 assert_equal "UTF-8", str.encoding.to_s
100 else
101 assert_equal "Texte encod en ISO-8859-1.", str
102 end
99 end
100 assert_equal "Texte encod? en ISO-8859-1.", str
103 end
101 end
104 end
102 end
105 end
103 end
General Comments 0
You need to be logged in to leave comments. Login now