@@ -245,7 +245,21 class Changeset < ActiveRecord::Base | |||
|
245 | 245 | private |
|
246 | 246 | |
|
247 | 247 | def self.to_utf8(str, encoding) |
|
248 |
return str if str. |
|
|
248 | return str if str.nil? | |
|
249 | str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding) | |
|
250 | return str if str.empty? | |
|
251 | str.force_encoding("UTF-8") if str.respond_to?(:force_encoding) | |
|
252 | if str.respond_to?(:force_encoding) | |
|
253 | enc = encoding.blank? ? "UTF-8" : encoding | |
|
254 | if enc != "UTF-8" | |
|
255 | str.force_encoding(enc) | |
|
256 | str = str.encode("UTF-8") | |
|
257 | end | |
|
258 | if ! str.valid_encoding? | |
|
259 | str = str.encode("US-ASCII", :invalid => :replace, | |
|
260 | :undef => :replace, :replace => '?').encode("UTF-8") | |
|
261 | end | |
|
262 | else | |
|
249 | 263 | unless encoding.blank? || encoding == 'UTF-8' |
|
250 | 264 | begin |
|
251 | 265 | str = Iconv.conv('UTF-8', encoding, str) |
@@ -253,13 +267,6 class Changeset < ActiveRecord::Base | |||
|
253 | 267 | # do nothing here |
|
254 | 268 | end |
|
255 | 269 | end |
|
256 | if str.respond_to?(:force_encoding) | |
|
257 | str.force_encoding('UTF-8') | |
|
258 | if ! str.valid_encoding? | |
|
259 | str = str.encode("US-ASCII", :invalid => :replace, | |
|
260 | :undef => :replace, :replace => '?').encode("UTF-8") | |
|
261 | end | |
|
262 | else | |
|
263 | 270 | # removes invalid UTF8 sequences |
|
264 | 271 | begin |
|
265 | 272 | str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] |
@@ -269,9 +269,9 class ChangesetTest < ActiveSupport::TestCase | |||
|
269 | 269 | def test_comments_should_be_converted_all_latin1_to_utf8 |
|
270 | 270 | s1 = "\xC2\x80" |
|
271 | 271 | s2 = "\xc3\x82\xc2\x80" |
|
272 | s4 = s2.dup | |
|
272 | 273 | if s1.respond_to?(:force_encoding) |
|
273 | 274 | s3 = s1.dup |
|
274 | s4 = s2.dup | |
|
275 | 275 | s1.force_encoding('ASCII-8BIT') |
|
276 | 276 | s2.force_encoding('ASCII-8BIT') |
|
277 | 277 | s3.force_encoding('ISO-8859-1') |
@@ -289,7 +289,7 class ChangesetTest < ActiveSupport::TestCase | |||
|
289 | 289 | :scmid => '12345', |
|
290 | 290 | :comments => s1) |
|
291 | 291 | assert( c.save ) |
|
292 |
assert_equal s |
|
|
292 | assert_equal s4, c.comments | |
|
293 | 293 | end |
|
294 | 294 | |
|
295 | 295 | def test_identifier |
General Comments 0
You need to be logged in to leave comments.
Login now