summaryrefslogtreecommitdiffstats
path: root/app/models/changeset.rb
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2011-04-09 05:41:12 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2011-04-09 05:41:12 +0000
commite297c1c24447c1236b885025386eccb8bc28e5ac (patch)
tree02231d95e727b86a50235551ff5b7cedbfc04662 /app/models/changeset.rb
parent1ef54041da9c33d977c6fb95b2cb0ac0e4ae5519 (diff)
downloadredmine-e297c1c24447c1236b885025386eccb8bc28e5ac.tar.gz
redmine-e297c1c24447c1236b885025386eccb8bc28e5ac.zip
scm: not use Iconv for log converting in Ruby 1.9 and fix tests fails in Ruby 1.9.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5367 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/changeset.rb')
-rw-r--r--app/models/changeset.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 59b2302ac..7039d9905 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -245,21 +245,28 @@ class Changeset < ActiveRecord::Base
private
def self.to_utf8(str, encoding)
- return str if str.blank?
- unless encoding.blank? || encoding == 'UTF-8'
- begin
- str = Iconv.conv('UTF-8', encoding, str)
- rescue Iconv::Failure
- # do nothing here
- end
- end
+ return str if str.nil?
+ str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
+ return str if str.empty?
+ str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
if str.respond_to?(:force_encoding)
- str.force_encoding('UTF-8')
+ enc = encoding.blank? ? "UTF-8" : encoding
+ if enc != "UTF-8"
+ str.force_encoding(enc)
+ str = str.encode("UTF-8")
+ end
if ! str.valid_encoding?
str = str.encode("US-ASCII", :invalid => :replace,
:undef => :replace, :replace => '?').encode("UTF-8")
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
begin
str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]