Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling Unicode Character 'LINE SEPARATOR' (U+2028) #610

Closed
jlachowski opened this Issue Apr 3, 2018 · 5 comments

Comments

4 participants
@jlachowski
Copy link

jlachowski commented Apr 3, 2018

WeasyPrint does not handle text with the Unicode Character 'LINE SEPARATOR' (U+2028) in it, resulting in a crash:

File "/usr/local/lib/python2.7/dist-packages/weasyprint/__init__.py", line 181, in write_pdf
presentational_hints=presentational_hints).write_pdf(
File "/usr/local/lib/python2.7/dist-packages/weasyprint/__init__.py", line 146, in render
self, stylesheets, enable_hinting, presentational_hints)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/document.py", line 326, in _render
[Page(p, enable_hinting) for p in page_boxes],
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/__init__.py", line 53, in layout_document
pages = list(make_all_pages(context, root_box))
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/pages.py", line 570, in make_all_pages
page_number)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/pages.py", line 516, in make_page
positioned_boxes, positioned_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 70, in block_level_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 98, in block_box_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 603, in block_container_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 70, in block_level_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 98, in block_box_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 603, in block_container_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 70, in block_level_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 98, in block_box_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 603, in block_container_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 70, in block_level_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 98, in block_box_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 603, in block_container_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 70, in block_level_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 98, in block_box_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 603, in block_container_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 70, in block_level_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 92, in block_box_layout
context, box, (containing_block.width, containing_block.height))
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py", line 740, in table_wrapper_width
auto_table_layout(context, wrapper, containing_block)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py", line 528, in auto_table_layout
table_and_columns_preferred_widths(context, box, outer=False)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/preferred.py", line 390, in table_and_columns_preferred_widths
min_content_widths[i], min_content_width(context, cell))
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/preferred.py", line 53, in min_content_width
return block_min_content_width(context, box, outer)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/preferred.py", line 163, in block_min_content_width
context, box, min_content_width, outer)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/preferred.py", line 99, in _block_content_width
if not child.is_absolutely_positioned()]
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/preferred.py", line 58, in min_content_width
context, box, outer, is_line_start=True)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/preferred.py", line 187, in inline_min_content_width
widths[-1] -= trailing_whitespace_size(context, box)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/preferred.py", line 623, in trailing_whitespace_size
assert resume is None
AssertionError

@liZe liZe added the bug label Apr 3, 2018

@Tontyna

This comment has been minimized.

Copy link
Contributor

Tontyna commented Apr 21, 2018

Could you provide a crashing html-snippet?

@liZe

This comment has been minimized.

Copy link
Member

liZe commented Aug 2, 2018

@jlachowski ping?

@EtienneDG

This comment has been minimized.

Copy link

EtienneDG commented Mar 1, 2019

Hello,

Sorry to revive a 1 year old issue, but I got the same issue and I found why it's not working on my side.

My virtualenv : python 2.7.15
jinja2==2.10
WeasyPrint==0.42.3

My python code :

rendered_template = self.jinja_env.get_template('pdf/proposal_for_booker.html') \
     # having a space at the end of description makes the render crash
    .render(description=u'This is \noh this end ')
return HTML(string=rendered_template).write_pdf()

My html code :

<html>
<head>
  <style>

    td, th {
      display: table-cell;
      vertical-align: inherit;
      padding: 10px 10px;
      white-space: pre-line;
    }

  </style>
</head>
  <body>
    <div>
      <table class="table">
        <tbody>
          <tr>
            <td>{{ description }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>

The bug seems to be happening when those two conditions are met :

  • description ends with a whitespace
  • td elements have white-space:pre-line as a styling rule.

Switching from pre-line to pre-wrap is doing the trick for me without breaking the pdf layout.

@liZe

This comment has been minimized.

Copy link
Member

liZe commented Mar 1, 2019

Hello,

Hello!

Sorry to revive a 1 year old issue, but I got the same issue and I found why it's not working on my side.

Thanks for the example, I can reproduce with the current master branch.

@liZe liZe closed this in 51dcbe3 Mar 1, 2019

@liZe liZe added this to the 46 milestone Mar 1, 2019

@liZe

This comment has been minimized.

Copy link
Member

liZe commented Mar 1, 2019

@EtienneDG It's fixed now.

If you're stuck with Python 2.7 (and thus can't install recent versions of WeasyPrint), it should be easy for you to backport 51dcbe3 manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.