##// END OF EJS Templates
scm: replace invalid utf-8 sequences in comments instead of stripping on Ruby 1.8....
Toshi MARUYAMA -
r5253:6536c53e0973
parent child
Show More
@@ -255,8 +255,8 class Changeset < ActiveRecord::Base
255 255 str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
256 256 return str
257 257 end
258 if str.respond_to?(:force_encoding)
259 258 enc = encoding.blank? ? "UTF-8" : encoding
259 if str.respond_to?(:force_encoding)
260 260 if enc != "UTF-8"
261 261 str.force_encoding(enc)
262 262 str = str.encode("UTF-8", :invalid => :replace,
@@ -269,19 +269,18 class Changeset < ActiveRecord::Base
269 269 end
270 270 end
271 271 else
272 unless encoding.blank? || encoding == 'UTF-8'
273 begin
274 str = Iconv.conv('UTF-8', encoding, str)
275 rescue Iconv::Failure
276 # do nothing here
277 end
278 end
279 # removes invalid UTF8 sequences
272 ic = Iconv.new('UTF-8', enc)
273 txtar = ""
280 274 begin
281 str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
282 rescue Iconv::InvalidEncoding
283 # "UTF-8//IGNORE" is not supported on some OS
284 end
275 txtar += ic.iconv(str)
276 rescue Iconv::IllegalSequence
277 txtar += $!.success
278 str = '?' + $!.failed[1,$!.failed.length]
279 retry
280 rescue
281 txtar += $!.success
282 end
283 str = txtar
285 284 end
286 285 str
287 286 end
@@ -21,7 +21,8 require File.expand_path('../../test_helper', __FILE__)
21 21
22 22 class ChangesetTest < ActiveSupport::TestCase
23 23 fixtures :projects, :repositories, :issues, :issue_statuses,
24 :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :member_roles, :trackers
24 :changesets, :changes, :issue_categories, :enumerations,
25 :custom_fields, :custom_values, :users, :members, :member_roles, :trackers
25 26
26 27 def setup
27 28 end
@@ -250,13 +251,14 class ChangesetTest < ActiveSupport::TestCase
250 251 assert_equal str_utf8, c.comments
251 252 end
252 253
253 def test_invalid_utf8_sequences_in_comments_should_be_stripped
254 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
254 255 proj = Project.find(3)
255 256 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
256 257 str = "Texte encod\xe9 en ISO-8859-1."
257 258 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
258 259 r = Repository::Bazaar.create!(
259 :project => proj, :url => '/tmp/test/bazaar',
260 :project => proj,
261 :url => '/tmp/test/bazaar',
260 262 :log_encoding => 'UTF-8' )
261 263 assert r
262 264 c = Changeset.new(:repository => r,
@@ -265,14 +267,10 class ChangesetTest < ActiveSupport::TestCase
265 267 :scmid => '12345',
266 268 :comments => str)
267 269 assert( c.save )
268 if str.respond_to?(:force_encoding)
269 270 assert_equal "Texte encod? en ISO-8859-1.", c.comments
270 else
271 assert_equal "Texte encod en ISO-8859-1.", c.comments
272 end
273 271 end
274 272
275 def test_invalid_utf8_sequences_in_comments_should_be_stripped_ja_jis
273 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
276 274 proj = Project.find(3)
277 275 str = "test\xb5\xfetest\xb5\xfe"
278 276 if str.respond_to?(:force_encoding)
@@ -289,11 +287,7 class ChangesetTest < ActiveSupport::TestCase
289 287 :scmid => '12345',
290 288 :comments => str)
291 289 assert( c.save )
292 if str.respond_to?(:force_encoding)
293 290 assert_equal "test??test??", c.comments
294 else
295 assert_equal "testtest", c.comments
296 end
297 291 end
298 292
299 293 def test_comments_should_be_converted_all_latin1_to_utf8
General Comments 0
You need to be logged in to leave comments. Login now