Skip to content

Commit

Permalink
Don’t crash when fixed elements aren’t displayed yet in aborted line
Browse files Browse the repository at this point in the history
Fix #1806.
  • Loading branch information
liZe committed Feb 13, 2023
1 parent 16cf66c commit dc7c2cb
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
98 changes: 98 additions & 0 deletions tests/draw/test_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,101 @@ def test_absolute_pages_counter_orphans(assert_pixels):
</style>
a a a <div>a a a</div> a <div>a a a</div>
''')


@assert_no_logs
def test_absolute_in_inline(assert_pixels):
assert_pixels('''
______
_GG___
_GG___
_GG___
_GG___
______
______
______
______
______
_RR___
_RR___
_RR___
_RR___
_BB___
_BB___
______
______
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
margin: 1px;
size: 6px 9px;
}
body {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
orphans: 2;
widows: 2;
}
p {
color: lime;
}
div {
color: blue;
position: absolute;
}
</style>
<p>a a</p> a a <div>a</div>
''')


@assert_no_logs
def test_fixed_in_inline(assert_pixels):
assert_pixels('''
______
_GG___
_GG___
_GG___
_GG___
_BB___
_BB___
______
______
______
_RR___
_RR___
_RR___
_RR___
_BB___
_BB___
______
______
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
margin: 1px;
size: 6px 9px;
}
body {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
orphans: 2;
widows: 2;
}
p {
color: lime;
}
div {
color: blue;
position: fixed;
}
</style>
<p>a a</p> a a <div>a</div>
''')
3 changes: 1 addition & 2 deletions weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,9 +1032,8 @@ def remove_placeholders(context, box_list, absolute_boxes, fixed_boxes):
remove_placeholders(
context, box.children, absolute_boxes, fixed_boxes)
if box.style['position'] == 'absolute' and box in absolute_boxes:
# box is not in absolute_boxes if its parent has position: relative
absolute_boxes.remove(box)
elif box.style['position'] == 'fixed':
elif box.style['position'] == 'fixed' and box in fixed_boxes:
fixed_boxes.remove(box)
if box.footnote:
context.unlayout_footnote(box.footnote)
Expand Down

0 comments on commit dc7c2cb

Please sign in to comment.