git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5715 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
a5d528c6c2
commit
e25dd95389
|
@ -455,8 +455,12 @@ module Redmine
|
||||||
txt ||= ''
|
txt ||= ''
|
||||||
if txt.respond_to?(:force_encoding)
|
if txt.respond_to?(:force_encoding)
|
||||||
txt.force_encoding('UTF-8')
|
txt.force_encoding('UTF-8')
|
||||||
|
if l(:general_pdf_encoding).upcase != 'UTF-8'
|
||||||
txt = txt.encode(l(:general_pdf_encoding), :invalid => :replace,
|
txt = txt.encode(l(:general_pdf_encoding), :invalid => :replace,
|
||||||
:undef => :replace, :replace => '?')
|
:undef => :replace, :replace => '?')
|
||||||
|
else
|
||||||
|
txt = Redmine::CodesetUtil.replace_invalid_utf8(txt)
|
||||||
|
end
|
||||||
txt.force_encoding('ASCII-8BIT')
|
txt.force_encoding('ASCII-8BIT')
|
||||||
else
|
else
|
||||||
ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
|
ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
|
||||||
|
|
|
@ -58,4 +58,44 @@ class PdfTest < ActiveSupport::TestCase
|
||||||
Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_3)
|
Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_en
|
||||||
|
set_language_if_valid 'en'
|
||||||
|
assert_equal 'UTF-8', l(:general_pdf_encoding)
|
||||||
|
str1 = "Texte encod\xe9 en ISO-8859-1"
|
||||||
|
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
|
||||||
|
str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
|
||||||
|
str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
|
||||||
|
if RUBY_VERSION < '1.9'
|
||||||
|
ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8')
|
||||||
|
end
|
||||||
|
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str1)
|
||||||
|
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str2)
|
||||||
|
if txt_1.respond_to?(:force_encoding)
|
||||||
|
assert_equal "ASCII-8BIT", txt_1.encoding.to_s
|
||||||
|
assert_equal "ASCII-8BIT", txt_2.encoding.to_s
|
||||||
|
end
|
||||||
|
assert_equal "Texte encod? en ISO-8859-1", txt_1
|
||||||
|
assert_equal "?a?b?c?d?e test", txt_2
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja
|
||||||
|
set_language_if_valid 'ja'
|
||||||
|
assert_equal 'CP932', l(:general_pdf_encoding)
|
||||||
|
str1 = "Texte encod\xe9 en ISO-8859-1"
|
||||||
|
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
|
||||||
|
str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
|
||||||
|
str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
|
||||||
|
if RUBY_VERSION < '1.9'
|
||||||
|
ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8')
|
||||||
|
end
|
||||||
|
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str1)
|
||||||
|
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str2)
|
||||||
|
if txt_1.respond_to?(:force_encoding)
|
||||||
|
assert_equal "ASCII-8BIT", txt_1.encoding.to_s
|
||||||
|
assert_equal "ASCII-8BIT", txt_2.encoding.to_s
|
||||||
|
end
|
||||||
|
assert_equal "Texte encod? en ISO-8859-1", txt_1
|
||||||
|
assert_equal "?a?b?c?d?e test", txt_2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue