Skip to content

Commit

Permalink
Don’t stop rendering SVG when CSS parsing fails
Browse files Browse the repository at this point in the history
Fix #1625.
  • Loading branch information
liZe committed Apr 28, 2022
1 parent 0e3129d commit 0fcc7de
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion weasyprint/svg/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cssselect2
import tinycss2

from ..logger import LOGGER
from .utils import parse_url


Expand Down Expand Up @@ -72,7 +73,13 @@ def parse_stylesheets(tree, url):
for rule in find_stylesheets_rules(tree, stylesheet, url):
normal_declarations, important_declarations = parse_declarations(
rule.content)
for selector in cssselect2.compile_selector_list(rule.prelude):
try:
selectors = cssselect2.compile_selector_list(rule.prelude)
except cssselect2.parser.SelectorError as exception:
LOGGER.warning(
'Failed to apply CSS rule in SVG rule: %s', exception)
break
for selector in selectors:
if (selector.pseudo_element is None and
not selector.never_matches):
if normal_declarations:
Expand Down

0 comments on commit 0fcc7de

Please sign in to comment.