From e38bff8b99687583f5789966ac9a264d63e608f7 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 17 Jun 2022 10:07:28 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20crash=20when=20inherited=20SVG?= =?UTF-8?q?=20attributes=20are=20not=20set=20on=20the=20parent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/draw/svg/test_shapes.py | 23 +++++++++++++++++++++++ weasyprint/svg/__init__.py | 8 ++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/draw/svg/test_shapes.py b/tests/draw/svg/test_shapes.py index 72c725765..a3a3a58b0 100644 --- a/tests/draw/svg/test_shapes.py +++ b/tests/draw/svg/test_shapes.py @@ -435,3 +435,26 @@ def test_rect_width_height_zero(assert_pixels): ''') + + +@assert_no_logs +def test_rect_fill_inherit(assert_pixels): + assert_pixels(''' + _________ + _________ + __KKKKK__ + __KKKKK__ + __KKKKK__ + __KKKKK__ + __KKKKK__ + _________ + _________ + ''', ''' + + + + + ''') diff --git a/weasyprint/svg/__init__.py b/weasyprint/svg/__init__.py index bff03a618..cb434bfed 100644 --- a/weasyprint/svg/__init__.py +++ b/weasyprint/svg/__init__.py @@ -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'):