From 51dcbe36a509311a7d549f65c6499e46cf3f3bdf Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 1 Mar 2019 16:03:04 +0100 Subject: [PATCH] Don't crash when removing trailing whitespaces on pre-line blocks Fix #610. --- weasyprint/layout/preferred.py | 7 +++++-- weasyprint/tests/test_text.py | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/weasyprint/layout/preferred.py b/weasyprint/layout/preferred.py index 69041a951..5a569fad9 100644 --- a/weasyprint/layout/preferred.py +++ b/weasyprint/layout/preferred.py @@ -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 diff --git a/weasyprint/tests/test_text.py b/weasyprint/tests/test_text.py index c82fa80fc..19157389f 100644 --- a/weasyprint/tests/test_text.py +++ b/weasyprint/tests/test_text.py @@ -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(''' +
This is + oh this end
+ ''')