From: Jean-Philippe Lang Date: Mon, 18 Feb 2013 21:39:17 +0000 (+0000) Subject: Don't use iconv with ruby1.9 (#12787). X-Git-Tag: 2.3.0~79 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=59c704dcd2a22c43a51a588ea82d85dd3d58ce87;p=redmine.git 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 --- 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