Defect #117

'\'(char code 0x5c) handling is improper in PDF output

Added by Go MAEDA about 10 years ago. Updated about 10 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Resolution: Affected version:

Description

When createing PDF file, '\' may have to be escaped like '\\'.
Redmine perhaps does not escape '\', so we sometimes get malformed output.

Because of this problem, issues which contains specific Japanese multi-byte character whose second byte character is
0x5c are not properly exported PDF file (gets malformed output).

[How to reproduce]

1. Create new issue. Description of the issue is following.

printf("Hello\n");
printf("World.\\n");

2. Export it to PDF. You will see malformed output like this.

printf("Hello ");
printf("World.\n");

Associated revisions

Revision 813
Added by Jean-Philippe Lang about 10 years ago

Fixed: improper 0x5c char handling in PDF output (Go Maeda).

Revision 5337
Added by Toshi MARUYAMA over 6 years ago

PDF: create new unit lib pdf test and add '0x5c'(backslash) handling test (#61, #117).

Japanese Shift_JIS and Traditional Chinese Big5 have '0x5c'(backslash) problem.

Revision 5339
Added by Toshi MARUYAMA over 6 years ago

PDF: set language 'ja' in '0x5c'(backslash) handling unit lib test (#61, #117).

Revision 5341
Added by Toshi MARUYAMA over 6 years ago

PDF: fix \\(double backslashes) handling of FPDF ANSI (#61, #117).

Revision 5342
Added by Toshi MARUYAMA over 6 years ago

PDF: add \\(double backslashes) handling of FPDF ANSI test in unit lib test (#61, #117).

Revision 5343
Added by Toshi MARUYAMA over 6 years ago

PDF: Ruby 1.9 compatibility of '0x5c'(backslash) handling in FPDF ANSI (#61, #117).

Japanese Shift_JIS and Traditional Chinese Big5 have '0x5c'(backslash) problem.

Revision 5344
Added by Toshi MARUYAMA over 6 years ago

PDF: add test of Ruby 1.9 compatibility of '0x5c'(backslash) handling in FPDF ANSI (#61, #117).

Japanese Shift_JIS and Traditional Chinese Big5 have '0x5c'(backslash) problem.

History

#1 Updated by Aruo Miura about 10 years ago

No problem.
Thanks for your work.

#2 Updated by Jean-Philippe Lang about 10 years ago

Oh, I'm sorry. I didn't notice that the patch was from someone
else.

Big thanks to Aruo Miura :-)

#3 Updated by Go MAEDA about 10 years ago

Thanks for your work. The fix is of great benefit to MBCS users.

Although the patch's author is Aruo Miura, my name is
written in svn commit log instead of Miura.

#4 Updated by Jean-Philippe Lang about 10 years ago

Your fix (slightly edited) is committed in r813.
Thanks for your help.

#5 Updated by Aruo Miura about 10 years ago

Hi.
I make patch for this problem.
This one can resolve 2 problems:
A:Iconv can't convert multi-byte string include '\'.
B:multi-byte character include 0x5c can't show in PDF.

I check only environments:
WindowsXP SP2/Japanese
ruby 1.8.6-p110
rails 1.2.3
redmine rev.781

Index: ifpdf_helper.rb
=================================================================
==
--- ifpdf_helper.rb     (Revision 781)
+++ ifpdf_helper.rb     (Working copy)
@@ -53,7 +53,13 @@
     def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
       @ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
       txt = begin
-        @ic.iconv(txt)
+        txtar = txt.split('\\')
+        txtar << '' if txt[-1] == ?\\
+        txtar2 = []
+        txtar.each{|x|
+          txtar2 << @ic.iconv(x)
+        }
+        txtar2.join('\\').gsub(/\\/, "\\\\\\\\")
       rescue
         txt
       end

Also available in: Atom PDF