]> source.dussan.org Git - redmine.git/commitdiff
PDF: replace all non ASCII characters to '?' if Iconv error raise in JRuby (#8569...
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Thu, 9 Jun 2011 03:41:26 +0000 (03:41 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Thu, 9 Jun 2011 03:41:26 +0000 (03:41 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6024 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/export/pdf.rb
test/unit/lib/redmine/export/pdf_test.rb

index 3203c19a81cc0ebc9ade680fe22200ab35b23404..97176a7f9e1873b3204ab5123305323cd8497468 100644 (file)
@@ -408,6 +408,13 @@ module Redmine
               txt = Redmine::CodesetUtil.replace_invalid_utf8(txt)
             end
             txt.force_encoding('ASCII-8BIT')
+          elsif RUBY_PLATFORM == 'java'
+            begin
+              ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
+              txt = ic.iconv(txt)
+            rescue
+              txt = txt.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
+            end
           else
             ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
             txtar = ""
index acb46ca69a4265b0942e04f2c15f10f764a8bf19..ec1f3fd7bbe87ca497ed51badb7c6c7306b1de7a 100644 (file)
@@ -57,6 +57,13 @@ class PdfTest < ActiveSupport::TestCase
       assert_equal "ASCII-8BIT", txt_1.encoding.to_s
       assert_equal "ASCII-8BIT", txt_2.encoding.to_s
       assert_equal "ASCII-8BIT", txt_3.encoding.to_s
+    elsif RUBY_PLATFORM == 'java'
+      assert_equal "??",
+                   Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1)
+      assert_equal "???",
+                   Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_2)
+      assert_equal "????",
+                   Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_3)
     else
       assert_equal "???\x91\xd4",
                    Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1)