From 958140734b8639fc95f5784eea62e77ed4b0d5a9 Mon Sep 17 00:00:00 2001 From: grewn0uille Date: Thu, 12 Sep 2019 18:23:29 +0200 Subject: [PATCH] Fix same_broken_child The old code assumed that both skip stacks were absolute, but for the second one previous children have already been skipped. We now check that we're in the first child at each level, meaning that we're still breaking the same child. Related to #923. --- weasyprint/layout/inlines.py | 15 ++++++++++----- weasyprint/tests/test_layout/test_inline.py | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/weasyprint/layout/inlines.py b/weasyprint/layout/inlines.py index 0fb8da66a..e474e71e0 100644 --- a/weasyprint/layout/inlines.py +++ b/weasyprint/layout/inlines.py @@ -1294,12 +1294,17 @@ def can_break_inside(box): return False -def same_broken_child(skip_stack_1, skip_stack_2): +def same_broken_child(original_skip_stack, relative_skip_stack): """Check that the skip stacks design the same text box.""" - while isinstance(skip_stack_1, tuple) and isinstance(skip_stack_2, tuple): - if skip_stack_1[1] is None and skip_stack_2[1] is None: + while (isinstance(original_skip_stack, tuple) and + isinstance(relative_skip_stack, tuple)): + if original_skip_stack[1] is None and relative_skip_stack[1] is None: + # The last levels of the two skip_stack are the same return True - if skip_stack_1[0] != skip_stack_2[0]: + if relative_skip_stack[0] != 0: + # If at the current level the skip_stack is not 0, it means that + # it is not the first child that has been cut return False - skip_stack_1, skip_stack_2 = skip_stack_1[1], skip_stack_2[1] + original_skip_stack = original_skip_stack[1] + relative_skip_stack = relative_skip_stack[1] return False diff --git a/weasyprint/tests/test_layout/test_inline.py b/weasyprint/tests/test_layout/test_inline.py index 4ba21e3dd..7a0e0abaa 100644 --- a/weasyprint/tests/test_layout/test_inline.py +++ b/weasyprint/tests/test_layout/test_inline.py @@ -361,6 +361,27 @@ def test_breaking_linebox_regression_9(): assert line2.children[1].text == 'ddd' +@assert_no_logs +def test_breaking_linebox_regression_10(): + # Regression test for https://github.com/Kozea/WeasyPrint/issues/923 + page, = parse( + '' + '

' + ' ' + ' xxxxxx YYY yyyyyy yyy' + ' ZZZZZZ zzzzz' + ' )x ' + '

') + html, = page.children + body, = html.children + p, = body.children + line1, line2, line3, line4 = p.children + assert line1.children[0].children[0].children[0].text == 'xxxxxx YYY' + assert line2.children[0].children[0].children[0].text == 'yyyyyy yyy' + assert line3.children[0].children[0].text == 'ZZZZZZ zzzzz' + assert line4.children[0].text == ')x' + + @assert_no_logs def test_linebox_text(): page, = parse('''