Skip to content

Commit 0fcc7de

Browse files
committed
Don’t stop rendering SVG when CSS parsing fails
Fix #1625.
1 parent 0e3129d commit 0fcc7de

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

weasyprint/svg/css.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import cssselect2
66
import tinycss2
77

8+
from ..logger import LOGGER
89
from .utils import parse_url
910

1011

@@ -72,7 +73,13 @@ def parse_stylesheets(tree, url):
7273
for rule in find_stylesheets_rules(tree, stylesheet, url):
7374
normal_declarations, important_declarations = parse_declarations(
7475
rule.content)
75-
for selector in cssselect2.compile_selector_list(rule.prelude):
76+
try:
77+
selectors = cssselect2.compile_selector_list(rule.prelude)
78+
except cssselect2.parser.SelectorError as exception:
79+
LOGGER.warning(
80+
'Failed to apply CSS rule in SVG rule: %s', exception)
81+
break
82+
for selector in selectors:
7683
if (selector.pseudo_element is None and
7784
not selector.never_matches):
7885
if normal_declarations:

0 commit comments

Comments
 (0)