Skip to content

Commit

Permalink
Display warnings for unknown at-rules or parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Jan 24, 2025
1 parent a52cfe1 commit f992fd5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions tests/css/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
['ERROR: Relative URI reference without a base URI']),
('@import "invalid-protocol://absolute-URL"',
['ERROR: Failed to load stylesheet at']),
('test', ['WARNING: Parse error']),
('@test', ['WARNING: Unknown empty rule']),
('@test {}', ['WARNING: Unknown rule']),
))
def test_warnings(source, messages):
with capture_logs() as logs:
Expand Down
20 changes: 17 additions & 3 deletions weasyprint/css/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,18 @@ def preprocess_stylesheet(device_media_type, base_url, stylesheet_rules, url_fet
ignore_imports=False):
"""Do what can be done early on stylesheet, before being in a document."""
for rule in stylesheet_rules:
if getattr(rule, 'content', None) is None and (
rule.type != 'at-rule' or rule.lower_at_keyword != 'import'):
continue
if getattr(rule, 'content', None) is None:
if rule.type == 'error':
LOGGER.warning(
"Parse error at %d:%d: %s",
rule.source_line, rule.source_column, rule.message)
if rule.type != 'at-rule':
continue
if rule.lower_at_keyword != 'import':
LOGGER.warning(
"Unknown empty rule %s at %d:%d",
rule, rule.source_line, rule.source_column)
continue

if rule.type == 'qualified-rule':
try:
Expand Down Expand Up @@ -1096,6 +1105,11 @@ def preprocess_stylesheet(device_media_type, base_url, stylesheet_rules, url_fet

counter_style[name] = counter

else:
LOGGER.warning(
"Unknown rule %s at %d:%d",
rule, rule.source_line, rule.source_column)


def get_all_computed_styles(html, user_stylesheets=None, presentational_hints=False,
font_config=None, counter_style=None, page_rules=None,
Expand Down

0 comments on commit f992fd5

Please sign in to comment.