##// END OF EJS Templates
Don't use Iconv with ruby1.9 (#12787)....
Jean-Philippe Lang -
r10947:ff53a9cfe18d
parent child
Show More
@@ -1,4 +1,6
1 require 'iconv'
1 if RUBY_VERSION < '1.9'
2 require 'iconv'
3 end
2
4
3 module Redmine
5 module Redmine
4 module CodesetUtil
6 module CodesetUtil
@@ -100,10 +102,17 module Redmine
100 end
102 end
101 encodings = Setting.repositories_encodings.split(',').collect(&:strip)
103 encodings = Setting.repositories_encodings.split(',').collect(&:strip)
102 encodings.each do |encoding|
104 encodings.each do |encoding|
103 begin
105 if str.respond_to?(:force_encoding)
104 return Iconv.conv('UTF-8', encoding, str)
106 str.force_encoding(encoding)
105 rescue Iconv::Failure
107 if str.valid_encoding?
106 # do nothing here and try the next encoding
108 return str.encode('UTF-8')
109 end
110 else
111 begin
112 return Iconv.conv('UTF-8', encoding, str)
113 rescue Iconv::Failure
114 # do nothing here and try the next encoding
115 end
107 end
116 end
108 end
117 end
109 str = self.replace_invalid_utf8(str)
118 str = self.replace_invalid_utf8(str)
@@ -17,12 +17,15
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 require 'iconv'
21 require 'tcpdf'
20 require 'tcpdf'
22 require 'fpdf/chinese'
21 require 'fpdf/chinese'
23 require 'fpdf/japanese'
22 require 'fpdf/japanese'
24 require 'fpdf/korean'
23 require 'fpdf/korean'
25
24
25 if RUBY_VERSION < '1.9'
26 require 'iconv'
27 end
28
26 module Redmine
29 module Redmine
27 module Export
30 module Export
28 module PDF
31 module PDF
@@ -86,7 +89,7 module Redmine
86
89
87 def SetTitle(txt)
90 def SetTitle(txt)
88 txt = begin
91 txt = begin
89 utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
92 utf16txt = to_utf16(txt)
90 hextxt = "<FEFF" # FEFF is BOM
93 hextxt = "<FEFF" # FEFF is BOM
91 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
94 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
92 hextxt << ">"
95 hextxt << ">"
@@ -109,6 +112,15 module Redmine
109 RDMPdfEncoding::rdm_from_utf8(txt, l(:general_pdf_encoding))
112 RDMPdfEncoding::rdm_from_utf8(txt, l(:general_pdf_encoding))
110 end
113 end
111
114
115 # Encodes an UTF-8 string to UTF-16BE
116 def to_utf16(str)
117 if str.respond_to?(:encode)
118 str.encode('UTF-16BE')
119 else
120 Iconv.conv('UTF-16BE', 'UTF-8', str)
121 end
122 end
123
112 def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
124 def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
113 Cell(w, h, fix_text_encoding(txt), border, ln, align, fill, link)
125 Cell(w, h, fix_text_encoding(txt), border, ln, align, fill, link)
114 end
126 end
@@ -154,7 +166,7 module Redmine
154
166
155 def bookmark_title(txt)
167 def bookmark_title(txt)
156 txt = begin
168 txt = begin
157 utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
169 utf16txt = to_utf16(txt)
158 hextxt = "<FEFF" # FEFF is BOM
170 hextxt = "<FEFF" # FEFF is BOM
159 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
171 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
160 hextxt << ">"
172 hextxt << ">"
@@ -17,6 +17,10
17
17
18 require 'cgi'
18 require 'cgi'
19
19
20 if RUBY_VERSION < '1.9'
21 require 'iconv'
22 end
23
20 module Redmine
24 module Redmine
21 module Scm
25 module Scm
22 module Adapters
26 module Adapters
@@ -16,7 +16,6
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../../../../test_helper', __FILE__)
18 require File.expand_path('../../../../../test_helper', __FILE__)
19 require 'iconv'
20
19
21 class PdfTest < ActiveSupport::TestCase
20 class PdfTest < ActiveSupport::TestCase
22 fixtures :users, :projects, :roles, :members, :member_roles,
21 fixtures :users, :projects, :roles, :members, :member_roles,
General Comments 0
You need to be logged in to leave comments. Login now