Commit a81049d5 authored by Toshi MARUYAMA's avatar Toshi MARUYAMA Committed by Eric Davis

scm: for log in Ruby 1.9, replace invalid UTF-8 to '?' instead of removing.

Refer r3466 #4773.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4926 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 0e342992
...@@ -253,12 +253,20 @@ class Changeset < ActiveRecord::Base ...@@ -253,12 +253,20 @@ class Changeset < ActiveRecord::Base
# do nothing here # do nothing here
end end
end end
# removes invalid UTF8 sequences if str.respond_to?(:force_encoding)
begin str.force_encoding('UTF-8')
Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] if ! str.valid_encoding?
rescue Iconv::InvalidEncoding str = str.encode("US-ASCII", :invalid => :replace,
# "UTF-8//IGNORE" is not supported on some OS :undef => :replace, :replace => '?').encode("UTF-8")
str end
else
# removes invalid UTF8 sequences
begin
str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
rescue Iconv::InvalidEncoding
# "UTF-8//IGNORE" is not supported on some OS
end
end end
str
end end
end end
...@@ -216,8 +216,13 @@ class ChangesetTest < ActiveSupport::TestCase ...@@ -216,8 +216,13 @@ class ChangesetTest < ActiveSupport::TestCase
def test_invalid_utf8_sequences_in_comments_should_be_stripped def test_invalid_utf8_sequences_in_comments_should_be_stripped
with_settings :commit_logs_encoding => 'UTF-8' do with_settings :commit_logs_encoding => 'UTF-8' do
c = Changeset.new c = Changeset.new
c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
assert_equal "Texte encod en ISO-8859-1.", c.comments c.comments = str
if str.respond_to?(:force_encoding)
assert_equal "Texte encod? en ISO-8859-1.", c.comments
else
assert_equal "Texte encod en ISO-8859-1.", c.comments
end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment