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