Skip to content

Commit

Permalink
Copy boxes when using them in stacking contexts
Browse files Browse the repository at this point in the history
If we don’t copy the boxes, rendering pages twice will fail because creating
stacking contexts can change the boxes’ children.

Fix #1473.
  • Loading branch information
liZe committed Nov 14, 2021
1 parent 58c9dbc commit aafb119
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/test_api.py
Expand Up @@ -975,3 +975,12 @@ def gzip_compress(data):
assert HTML(root_url + '/deflate').etree_element.get('test') == 'ok'
assert HTML(
root_url + '/raw-deflate').etree_element.get('test') == 'ok'


@assert_no_logs
def test_page_copy_relative():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/1473
document = FakeHTML(string='<div style="position: relative">a').render()
duplicated_pages = document.copy([*document.pages, *document.pages])
pngs = duplicated_pages.write_png(split_images=True)
assert pngs[0] == pngs[1]
2 changes: 1 addition & 1 deletion weasyprint/stacking.py
Expand Up @@ -136,7 +136,7 @@ def dispatch_children(box):
result = dispatch(child)
if result is not None:
new_children.append(result)
box.children = new_children
box = box.copy_with_children(new_children)
return box

box = dispatch_children(box)
Expand Down

0 comments on commit aafb119

Please sign in to comment.