From 6536c53e09735f81b11eeb70a744a94c48e0c977 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sat, 9 Apr 2011 09:31:14 +0000 Subject: 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 --- app/models/changeset.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'app/models/changeset.rb') 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 -- cgit v1.2.3