summaryrefslogtreecommitdiffstats
path: root/app/models/changeset.rb
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2011-04-09 09:31:14 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2011-04-09 09:31:14 +0000
commit6536c53e09735f81b11eeb70a744a94c48e0c977 (patch)
treeeed94ea69e06417b40f13c6b057fc7d06dc3614d /app/models/changeset.rb
parentb9ce061319133748c48c255bf6bd17b7dfe5ed9d (diff)
downloadredmine-6536c53e09735f81b11eeb70a744a94c48e0c977.tar.gz
redmine-6536c53e09735f81b11eeb70a744a94c48e0c977.zip
scm: replace invalid utf-8 sequences in comments instead of stripping on Ruby 1.8.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5373 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/changeset.rb')
-rw-r--r--app/models/changeset.rb23
1 files changed, 11 insertions, 12 deletions
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 9c0dc68de..869e9bad9 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -255,8 +255,8 @@ class Changeset < ActiveRecord::Base
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
return str
end
+ enc = encoding.blank? ? "UTF-8" : encoding
if str.respond_to?(:force_encoding)
- enc = encoding.blank? ? "UTF-8" : encoding
if enc != "UTF-8"
str.force_encoding(enc)
str = str.encode("UTF-8", :invalid => :replace,
@@ -269,19 +269,18 @@ class Changeset < ActiveRecord::Base
end
end
else
- unless encoding.blank? || encoding == 'UTF-8'
- begin
- str = Iconv.conv('UTF-8', encoding, str)
- rescue Iconv::Failure
- # do nothing here
- end
- end
- # removes invalid UTF8 sequences
+ ic = Iconv.new('UTF-8', enc)
+ txtar = ""
begin
- str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
- rescue Iconv::InvalidEncoding
- # "UTF-8//IGNORE" is not supported on some OS
+ txtar += ic.iconv(str)
+ rescue Iconv::IllegalSequence
+ txtar += $!.success
+ str = '?' + $!.failed[1,$!.failed.length]
+ retry
+ rescue
+ txtar += $!.success
end
+ str = txtar
end
str
end