diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-02-22 13:39:37 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-02-22 13:39:37 +0000 |
commit | 87a6d79b5be7da3a7814c2833fa05df65d151a96 (patch) | |
tree | c0a0248baed524a71ef1ed086bea295c30bb0ca2 /app/models/changeset.rb | |
parent | 9f50e6358371b60fab4245c956f02b1ae6490b56 (diff) | |
download | redmine-87a6d79b5be7da3a7814c2833fa05df65d151a96.tar.gz redmine-87a6d79b5be7da3a7814c2833fa05df65d151a96.zip |
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
Diffstat (limited to 'app/models/changeset.rb')
-rw-r--r-- | app/models/changeset.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/app/models/changeset.rb b/app/models/changeset.rb index d2e4a53f8..01220a21f 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -253,12 +253,20 @@ class Changeset < ActiveRecord::Base # do nothing here end end - # removes invalid UTF8 sequences - begin - Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] - rescue Iconv::InvalidEncoding - # "UTF-8//IGNORE" is not supported on some OS - str + if str.respond_to?(:force_encoding) + str.force_encoding('UTF-8') + if ! str.valid_encoding? + str = str.encode("US-ASCII", :invalid => :replace, + :undef => :replace, :replace => '?').encode("UTF-8") + 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 + str end end |