Skip to content

Commit

Permalink
Avoid endless recursion for variables in nested functions
Browse files Browse the repository at this point in the history
Fix #2370.
  • Loading branch information
liZe committed Feb 3, 2025
1 parent 44c97c1 commit caaa1a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/css/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,21 @@ def test_variable_in_function():
assert div2.children[0].children[0].children[0].text == '2'


@assert_no_logs
def test_variable_in_nested_function():
page, = render_pages('''
<style>
body { --var: 255 0 0 }
div { background-image: linear-gradient(rgba(var(--var))) }
</style>
<div></div>
''')
html, = page.children
body, = html.children
div, = body.children
assert div.style['background_image'][0][1].colors[0] == (1, 0, 0, 1)


@assert_no_logs
def test_variable_in_function_multiple_values():
page, = render_pages('''
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/css/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def resolve_var(computed, token, parent_style):
if token.lower_name != 'var':
arguments = []
for i, argument in enumerate(token.arguments):
if argument.type == 'function' and argument.lower_name == 'var':
if argument.type == 'function':
arguments.extend(resolve_var(computed, argument, parent_style))
else:
arguments.append(argument)
Expand Down

0 comments on commit caaa1a4

Please sign in to comment.