PDF: nil safe at fix_text_encoding(txt) of lib/redmine/export/pdf.rb.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5345 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-04-06 05:52:07 +00:00
parent 411c7100cb
commit d6e2e81f0c
2 changed files with 9 additions and 1 deletions

View File

@ -143,6 +143,7 @@ module Redmine
end end
def fix_text_encoding(txt) def fix_text_encoding(txt)
txt ||= ''
if txt.respond_to?(:force_encoding) if txt.respond_to?(:force_encoding)
txt.force_encoding('UTF-8') txt.force_encoding('UTF-8')
txt = txt.encode(l(:general_pdf_encoding), :invalid => :replace, txt = txt.encode(l(:general_pdf_encoding), :invalid => :replace,
@ -154,7 +155,7 @@ module Redmine
@ic.iconv(txt) @ic.iconv(txt)
rescue rescue
txt txt
end || '' end
end end
# 0x5c char handling # 0x5c char handling
txt.gsub(/\\/, "\\\\\\\\") txt.gsub(/\\/, "\\\\\\\\")

View File

@ -20,6 +20,13 @@ require File.expand_path('../../../../../test_helper', __FILE__)
class PdfTest < ActiveSupport::TestCase class PdfTest < ActiveSupport::TestCase
include Redmine::I18n include Redmine::I18n
def test_fix_text_encoding_nil
set_language_if_valid 'ja'
pdf = Redmine::Export::PDF::IFPDF.new('ja')
assert pdf
assert_equal '', pdf.fix_text_encoding(nil)
end
def test_fix_text_encoding_backslash_ascii def test_fix_text_encoding_backslash_ascii
set_language_if_valid 'ja' set_language_if_valid 'ja'
pdf = Redmine::Export::PDF::IFPDF.new('ja') pdf = Redmine::Export::PDF::IFPDF.new('ja')