From 59c704dcd2a22c43a51a588ea82d85dd3d58ce87 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 18 Feb 2013 21:39:17 +0000 Subject: [PATCH] Don't use iconv with ruby1.9 (#12787). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11440 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/tasks/migrate_from_mantis.rake | 15 ++++++++------- lib/tasks/migrate_from_trac.rake | 17 ++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/tasks/migrate_from_mantis.rake b/lib/tasks/migrate_from_mantis.rake index f0b65e2aa..465ca9958 100644 --- a/lib/tasks/migrate_from_mantis.rake +++ b/lib/tasks/migrate_from_mantis.rake @@ -18,7 +18,7 @@ desc 'Mantis migration script' require 'active_record' -require 'iconv' +require 'iconv' if RUBY_VERSION < '1.9' require 'pp' namespace :redmine do @@ -440,9 +440,7 @@ task :migrate_from_mantis => :environment do end def self.encoding(charset) - @ic = Iconv.new('UTF-8', charset) - rescue Iconv::InvalidEncoding - return false + @charset = charset end def self.establish_connection(params) @@ -454,9 +452,12 @@ task :migrate_from_mantis => :environment do end def self.encode(text) - @ic.iconv text - rescue - text + if RUBY_VERSION < '1.9' + @ic ||= Iconv.new('UTF-8', @charset) + @ic.iconv text + else + text.to_s.force_encoding(@charset).encode('UTF-8') + end end end diff --git a/lib/tasks/migrate_from_trac.rake b/lib/tasks/migrate_from_trac.rake index f48d205a4..923b0c620 100644 --- a/lib/tasks/migrate_from_trac.rake +++ b/lib/tasks/migrate_from_trac.rake @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require 'active_record' -require 'iconv' +require 'iconv' if RUBY_VERSION < '1.9' require 'pp' namespace :redmine do @@ -603,10 +603,7 @@ namespace :redmine do end def self.encoding(charset) - @ic = Iconv.new('UTF-8', charset) - rescue Iconv::InvalidEncoding - puts "Invalid encoding!" - return false + @charset = charset end def self.set_trac_directory(path) @@ -713,11 +710,13 @@ namespace :redmine do end end - private def self.encode(text) - @ic.iconv text - rescue - text + if RUBY_VERSION < '1.9' + @ic ||= Iconv.new('UTF-8', @charset) + @ic.iconv text + else + text.to_s.force_encoding(@charset).encode('UTF-8') + end end end -- 2.39.5