[reportlab-users] Possible bug in line wrapping

Robin Becker robin at reportlab.com
Mon Jul 27 05:28:51 EDT 2009


Roberto Alsina wrote:

> This is hard to trigger, but it seems that if there is a linebreak immediately

> after a link, the line doesn't break.

>

> Here is a test case which produced the attached PDF:

>

........

> go()

.......
yes that looks like a bug. Modifying your example shows it's the second a tag
that causes the problem


> from reportlab.platypus import SimpleDocTemplate, Paragraph

> from reportlab.lib.styles import ParagraphStyle

> from reportlab.lib.styles import getSampleStyleSheet

> from reportlab.lib.enums import TA_JUSTIFY

>

> def go():

> styles = getSampleStyleSheet()

> doc = SimpleDocTemplate("phello.pdf")

> style = styles['Normal']

> style.alignment=TA_JUSTIFY

> p1 = Paragraph('''PADDING PADDING PADDING PADDING PADDING PADDING The

> computer will always be better than you at parsing SQL

> and the bad guys have years of experience finding and using <a

> href="http://en.wikipedia.org/wiki/SQL_injection" color="navy">SQL

> injection attacks</a><a name="sql-injection-attacks"/> in

> ways you never even thought possible.''', style)

> p2 = Paragraph('''PADDING PADDING PADDING PADDING PADDING PADDING The

> computer will always be better than you at parsing SQL

> and the bad guys have years of experience finding and using <font color="navy">SQL

> injection attacks</font><a name="sql-injection-attacks"/> in

> ways you never even thought possible.''', style)

> p3 = Paragraph('''PADDING PADDING PADDING PADDING PADDING PADDING The

> computer will always be better than you at parsing SQL

> and the bad guys have years of experience finding and using <font color="navy">SQL

> injection attacks</font><font/>in

> ways you never even thought possible.''', style)

> doc.build([p1,p2,p3])

>

> go()


p1 and p2 cause a problem so the first <a> tag is not a cause as in p2 it's
replaced by <font>. In p3 eplacing the second <a> tag by <font/> allows the
break to happen.

Given that the anchor form was recently added I tried the following fix in
paragraph line 237 change

elif kind=='img':

to

elif kind in ('img','anchor'):

which seems to fix the problem at least in this example. Can you see if this
resolves the problem for you?
--
Robin Becker


More information about the reportlab-users mailing list