Skip to content

Commit

Permalink
Fixes #285 - Avoid crashing when handling @import rule
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed Dec 10, 2022
1 parent 9a43d4f commit 2eb5771
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
ChangeLog
=========

Unreleased
----------
- Avoid crash on ``@import`` rules in stylesheets. The rules are simply ignored
(#285).

1.4.1 (2022-08-05)
------------------
- No source code changes, only fixed a leftover set_trace() in the released code
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ Features
Known limitations
-----------------

- support for stylesheets is still experimental. Please report any
bug or shortcoming on the `svglib issue tracker`_.
- @import rules in stylesheets are ignored. CSS is supported, but the range
of supported attributes is still limited
- clipping is limited to single paths, no mask support
- color gradients are not supported (limitation of reportlab)
- SVG ``ForeignObject`` elements are not supported.
Expand Down
2 changes: 1 addition & 1 deletion svglib/svglib.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def add_styles(self, style_content):
)

for rule in rules:
if not rule.prelude:
if not rule.prelude or rule.type == 'at-rule':
continue
selectors = cssselect2.compile_selector_list(rule.prelude)
selector_string = tinycss2.serialize(rule.prelude)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,18 @@ def test_css_nth_of_type(self):
assert main_group.contents[0].contents[1].contents[0].fontName == 'Helvetica-Bold'
assert main_group.contents[0].contents[2].contents[0].fontName == 'Helvetica'

def test_import_rule_no_crash(self):
# Just test that svglib does not crash. Import rules are currently ignored.
drawing = drawing_from_svg('''
<svg>
<defs>
<style type="text/css">
@import url('https://fonts.example.org/css2?family=Ubuntu+Condensed');
</style>
</defs>
</svg>
''')


class TestGroupNode:
def test_svg_groups_have_svgid(self):
Expand Down

0 comments on commit 2eb5771

Please sign in to comment.