1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-09-11 20:47:56 +03:00

Don’t crash when currentColor is set on root svg tag

Fix #1740.
This commit is contained in:
Guillaume Ayoub 2022-10-15 16:19:37 +02:00
parent 1432669b30
commit 8c8d059052
2 changed files with 35 additions and 0 deletions

View File

@ -1,5 +1,7 @@
"""Test the currentColor value."""
import pytest
from ..testing_utils import assert_no_logs
@ -50,3 +52,31 @@ def test_current_color_4(assert_pixels):
color: lime; border: 1px solid; border-color: inherit }
</style>
<table><td>''')
@assert_no_logs
def test_current_color_svg_1(assert_pixels):
assert_pixels('KK\nKK', '''
<style>
@page { size: 2px }
svg { display: block }
</style>
<svg xmlns="http://www.w3.org/2000/svg"
width="2" height="2" fill="currentColor">
<rect width="2" height="2"></rect>
</svg>''')
@pytest.mark.xfail
@assert_no_logs
def test_current_color_svg_2(assert_pixels):
assert_pixels('GG\nGG', '''
<style>
@page { size: 2px }
svg { display: block }
body { color: lime }
</style>
<svg xmlns="http://www.w3.org/2000/svg"
width="2" height="2">
<rect width="2" height="2" fill="currentColor"></rect>
</svg>''')

View File

@ -288,6 +288,11 @@ class SVG:
self.tree = Node(wrapper, style)
self.url = url
# Replace 'currentColor' value
for key in COLOR_ATTRIBUTES:
if self.tree.get(key) == 'currentColor':
self.tree.attrib[key] = self.tree.get('color', 'black')
self.filters = {}
self.gradients = {}
self.images = {}