@@ -256,7 +256,8 class Changeset < ActiveRecord::Base | |||||
256 | enc = encoding.blank? ? "UTF-8" : encoding |
|
256 | enc = encoding.blank? ? "UTF-8" : encoding | |
257 | if enc != "UTF-8" |
|
257 | if enc != "UTF-8" | |
258 | str.force_encoding(enc) |
|
258 | str.force_encoding(enc) | |
259 |
str = str.encode("UTF-8" |
|
259 | str = str.encode("UTF-8", :invalid => :replace, | |
|
260 | :undef => :replace, :replace => '?') | |||
260 | end |
|
261 | end | |
261 | if ! str.valid_encoding? |
|
262 | if ! str.valid_encoding? | |
262 | str = str.encode("US-ASCII", :invalid => :replace, |
|
263 | str = str.encode("US-ASCII", :invalid => :replace, |
@@ -272,6 +272,30 class ChangesetTest < ActiveSupport::TestCase | |||||
272 | end |
|
272 | end | |
273 | end |
|
273 | end | |
274 |
|
274 | |||
|
275 | def test_invalid_utf8_sequences_in_comments_should_be_stripped_ja_jis | |||
|
276 | proj = Project.find(3) | |||
|
277 | str = "test\xb5\xfetest\xb5\xfe" | |||
|
278 | if str.respond_to?(:force_encoding) | |||
|
279 | str.force_encoding('ASCII-8BIT') | |||
|
280 | end | |||
|
281 | r = Repository::Bazaar.create!( | |||
|
282 | :project => proj, | |||
|
283 | :url => '/tmp/test/bazaar', | |||
|
284 | :log_encoding => 'ISO-2022-JP' ) | |||
|
285 | assert r | |||
|
286 | c = Changeset.new(:repository => r, | |||
|
287 | :committed_on => Time.now, | |||
|
288 | :revision => '123', | |||
|
289 | :scmid => '12345', | |||
|
290 | :comments => str) | |||
|
291 | assert( c.save ) | |||
|
292 | if str.respond_to?(:force_encoding) | |||
|
293 | assert_equal "test??test??", c.comments | |||
|
294 | else | |||
|
295 | assert_equal "testtest", c.comments | |||
|
296 | end | |||
|
297 | end | |||
|
298 | ||||
275 | def test_comments_should_be_converted_all_latin1_to_utf8 |
|
299 | def test_comments_should_be_converted_all_latin1_to_utf8 | |
276 | s1 = "\xC2\x80" |
|
300 | s1 = "\xC2\x80" | |
277 | s2 = "\xc3\x82\xc2\x80" |
|
301 | s2 = "\xc3\x82\xc2\x80" |
General Comments 0
You need to be logged in to leave comments.
Login now