Skip to content

Commit

Permalink
Don't crash when removing trailing whitespaces on pre-line blocks
Browse files Browse the repository at this point in the history
Fix #610.
  • Loading branch information
liZe committed Mar 1, 2019
1 parent f79110c commit 51dcbe3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions weasyprint/layout/preferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,14 @@ def trailing_whitespace_size(context, box):
if box.style['font_size'] == 0 or len(stripped_text) == len(box.text):
return 0
if stripped_text:
old_box, _, _ = split_text_box(context, box, None, 0)
resume = 0
while resume is not None:
old_resume = resume
old_box, resume, _ = split_text_box(context, box, None, resume)
assert old_box
stripped_box = box.copy_with_text(stripped_text)
stripped_box, resume, _ = split_text_box(
context, stripped_box, None, 0)
context, stripped_box, None, old_resume)
assert stripped_box is not None
assert resume is None
return old_box.width - stripped_box.width
Expand Down
9 changes: 9 additions & 0 deletions weasyprint/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,12 @@ def test_text_transform():
line5, = p5.children
text5, = line5.children
assert text5.text == 'hé lO1'


@assert_no_logs
def test_text_floating_pre_line():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/610
page, = render_pages('''
<div style="float: left; white-space: pre-line">This is
oh this end </div>
''')

0 comments on commit 51dcbe3

Please sign in to comment.