]> source.dussan.org Git - redmine.git/commitdiff
Don't use Iconv with ruby1.9 (#12787).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Jan 2013 21:27:36 +0000 (21:27 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Jan 2013 21:27:36 +0000 (21:27 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11177 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/codeset_util.rb
lib/redmine/export/pdf.rb
lib/redmine/scm/adapters/abstract_adapter.rb
test/unit/lib/redmine/export/pdf_test.rb

index b74a3a9e7e3e887479305b240f645388dc41e3df..41ea851536b5fe1ff2fc3eef3e56058442019b47 100644 (file)
@@ -1,4 +1,6 @@
-require 'iconv'
+if RUBY_VERSION < '1.9'
+  require 'iconv'
+end
 
 module Redmine
   module CodesetUtil
@@ -100,10 +102,17 @@ module Redmine
       end
       encodings = Setting.repositories_encodings.split(',').collect(&:strip)
       encodings.each do |encoding|
-        begin
-          return Iconv.conv('UTF-8', encoding, str)
-        rescue Iconv::Failure
-          # do nothing here and try the next encoding
+        if str.respond_to?(:force_encoding)
+          str.force_encoding(encoding)
+          if str.valid_encoding?
+            return str.encode('UTF-8')
+          end
+        else
+          begin
+            return Iconv.conv('UTF-8', encoding, str)
+          rescue Iconv::Failure
+            # do nothing here and try the next encoding
+          end
         end
       end
       str = self.replace_invalid_utf8(str)
index e650964eb404c40f749096ac216d1431144768e0..ff3993f728ceb834aebb49c6def94a3bddd142af 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-require 'iconv'
 require 'tcpdf'
 require 'fpdf/chinese'
 require 'fpdf/japanese'
 require 'fpdf/korean'
 
+if RUBY_VERSION < '1.9'
+  require 'iconv'
+end
+
 module Redmine
   module Export
     module PDF
@@ -86,7 +89,7 @@ module Redmine
 
         def SetTitle(txt)
           txt = begin
-            utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
+            utf16txt = to_utf16(txt)
             hextxt = "<FEFF"  # FEFF is BOM
             hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
             hextxt << ">"
@@ -109,6 +112,15 @@ module Redmine
           RDMPdfEncoding::rdm_from_utf8(txt, l(:general_pdf_encoding))
         end
 
+        # Encodes an UTF-8 string to UTF-16BE
+        def to_utf16(str)
+          if str.respond_to?(:encode)
+            str.encode('UTF-16BE')
+          else
+            Iconv.conv('UTF-16BE', 'UTF-8', str)
+          end
+        end
+
         def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
           Cell(w, h, fix_text_encoding(txt), border, ln, align, fill, link)
         end
@@ -154,7 +166,7 @@ module Redmine
 
         def bookmark_title(txt)
           txt = begin
-            utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
+            utf16txt = to_utf16(txt)
             hextxt = "<FEFF"  # FEFF is BOM
             hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
             hextxt << ">"
index 0f77d58d8cddb11b587038032b0aff08ad81ae6b..4458baa7e3825bbf92eda1ab74404e1313e5e8ce 100644 (file)
 
 require 'cgi'
 
+if RUBY_VERSION < '1.9'
+  require 'iconv'
+end
+
 module Redmine
   module Scm
     module Adapters
index 6046ab97c1eacd06d26da5518da257a1804aaf51..7b9488de0cd6302b488fb921e3a8b14edd2224d9 100644 (file)
@@ -16,7 +16,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 require File.expand_path('../../../../../test_helper', __FILE__)
-require 'iconv'
 
 class PdfTest < ActiveSupport::TestCase
   fixtures :users, :projects, :roles, :members, :member_roles,