Skip to content

Commit e38bff8

Browse files
committed
Don’t crash when inherited SVG attributes are not set on the parent
1 parent eadd5c0 commit e38bff8

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

tests/draw/svg/test_shapes.py

+23
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,26 @@ def test_rect_width_height_zero(assert_pixels):
435435
<rect x="2" y="2" width="5" height="5" fill="red" />
436436
</svg>
437437
''')
438+
439+
440+
@assert_no_logs
441+
def test_rect_fill_inherit(assert_pixels):
442+
assert_pixels('''
443+
_________
444+
_________
445+
__KKKKK__
446+
__KKKKK__
447+
__KKKKK__
448+
__KKKKK__
449+
__KKKKK__
450+
_________
451+
_________
452+
''', '''
453+
<style>
454+
@page { size: 9px }
455+
svg { display: block }
456+
</style>
457+
<svg width="9px" height="9px" xmlns="http://www.w3.org/2000/svg">
458+
<rect x="2" y="2" width="5" height="5" fill="inherit" />
459+
</svg>
460+
''')

weasyprint/svg/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,13 @@ def __iter__(self):
150150
child.attrib[key] = child.get('color', 'black')
151151

152152
# Handle 'inherit' values
153-
for key, value in child.attrib.items():
153+
for key, value in child.attrib.copy().items():
154154
if value == 'inherit':
155-
child.attrib[key] = self.get(key)
155+
value = self.get(key)
156+
if value is None:
157+
del child.attrib[key]
158+
else:
159+
child.attrib[key] = value
156160

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

0 commit comments

Comments
 (0)