Skip to content

Commit

Permalink
Don’t crash when inherited SVG attributes are not set on the parent
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Jun 17, 2022
1 parent eadd5c0 commit e38bff8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 23 additions & 0 deletions tests/draw/svg/test_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,26 @@ def test_rect_width_height_zero(assert_pixels):
<rect x="2" y="2" width="5" height="5" fill="red" />
</svg>
''')


@assert_no_logs
def test_rect_fill_inherit(assert_pixels):
assert_pixels('''
_________
_________
__KKKKK__
__KKKKK__
__KKKKK__
__KKKKK__
__KKKKK__
_________
_________
''', '''
<style>
@page { size: 9px }
svg { display: block }
</style>
<svg width="9px" height="9px" xmlns="http://www.w3.org/2000/svg">
<rect x="2" y="2" width="5" height="5" fill="inherit" />
</svg>
''')
8 changes: 6 additions & 2 deletions weasyprint/svg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ def __iter__(self):
child.attrib[key] = child.get('color', 'black')

# Handle 'inherit' values
for key, value in child.attrib.items():
for key, value in child.attrib.copy().items():
if value == 'inherit':
child.attrib[key] = self.get(key)
value = self.get(key)
if value is None:
del child.attrib[key]
else:
child.attrib[key] = value

# Fix text in text tags
if child.tag in ('text', 'textPath', 'a'):
Expand Down

0 comments on commit e38bff8

Please sign in to comment.