Skip to content

Commit

Permalink
Don’t crash on absolute SVG files with no intrinsic size
Browse files Browse the repository at this point in the history
Fix #1050.
  • Loading branch information
liZe committed Mar 14, 2020
1 parent a4511d0 commit fe7fd1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions weasyprint/layout/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ def block_replaced_box_layout(box, containing_block):
def block_level_width(box, containing_block):
"""Set the ``box`` width."""
# 'cb' stands for 'containing block'
cb_width = containing_block.width
if isinstance(containing_block, boxes.Box):
cb_width = containing_block.width
direction = containing_block.style['direction']
else:
cb_width = containing_block[0]
# TODO: what is the real text direction?
direction = 'ltr'

# http://www.w3.org/TR/CSS21/visudet.html#blockwidth

Expand Down Expand Up @@ -196,7 +202,7 @@ def block_level_width(box, containing_block):
margin_r = box.margin_right = 0
if width != 'auto' and margin_l != 'auto' and margin_r != 'auto':
# The equation is over-constrained.
if containing_block.style['direction'] == 'rtl' and not box.is_column:
if direction == 'rtl' and not box.is_column:
box.position_x += (
cb_width - paddings_plus_borders - width - margin_r - margin_l)
# Do nothing in ltr.
Expand Down
10 changes: 10 additions & 0 deletions weasyprint/tests/test_layout/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ def test_images_17():
assert img.height == 150


@assert_no_logs
def test_images_18():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1050
page, = parse('''
<img style="position: absolute" src="
data:image/svg+xml,
<svg viewBox='0 0 20 10'></svg>
">''')


@assert_no_logs
def test_linear_gradient():
red = (1, 0, 0, 1)
Expand Down

0 comments on commit fe7fd1c

Please sign in to comment.