Skip to content

Commit

Permalink
Fix imports with url() and quotes
Browse files Browse the repository at this point in the history
Fix #1299. Related to Kozea/tinycss2#33.
  • Loading branch information
liZe committed Feb 21, 2021
1 parent b1a8673 commit 6c1652e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions weasyprint/css/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ..urls import URLFetchingError, get_url_attribute, url_join
from . import computed_values, counters, media_queries
from .properties import INHERITED, INITIAL_NOT_COMPUTED, INITIAL_VALUES
from .utils import remove_whitespace
from .utils import get_url, remove_whitespace
from .validation import preprocess_declarations
from .validation.descriptors import preprocess_descriptors

Expand Down Expand Up @@ -838,9 +838,15 @@ def preprocess_stylesheet(device_media_type, base_url, stylesheet_rules,
continue

tokens = remove_whitespace(rule.prelude)
if tokens and tokens[0].type in ('url', 'string'):
url = tokens[0].value
else:
url = None
if tokens and len(tokens) == 1:
if tokens[0].type == 'string':
url = tokens[0].value
else:
url_tuple = get_url(tokens[0], base_url)
if url_tuple and url_tuple[1][0] == 'external':
url = url_tuple[1][1]
if url is None:
continue
media = media_queries.parse_media_query(tokens[1:])
if media is None:
Expand Down
2 changes: 2 additions & 0 deletions weasyprint/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ def test(html, blank=False):
'url(weasyprint-custom:foo/é_%e9_pattern)">')
test('<link rel=stylesheet href="weasyprint-custom:foo/bar.css"><body>')
test('<style>@import "weasyprint-custom:foo/bar.css";</style><body>')
test('<style>@import url(weasyprint-custom:foo/bar.css);</style><body>')
test('<style>@import url("weasyprint-custom:foo/bar.css");</style><body>')
test('<link rel=stylesheet href="weasyprint-custom:foo/bar.css"><body>')

with capture_logs() as logs:
Expand Down

0 comments on commit 6c1652e

Please sign in to comment.