Skip to content

Commit

Permalink
Fix currentcolor detection when parsing gradient color stops
Browse files Browse the repository at this point in the history
The bug has been introduced by CSS Color Level 4, that set the official
"currentColor"’s serialization string to lowercase "currentcolor".

Note that we still don’t draw the actual current color in this case (according
to the TODO above the fixed line) but black. At least it doesn’t crash
anymore.

Fix #2320.
  • Loading branch information
liZe committed Dec 4, 2024
1 parent e4ed732 commit db288a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/draw/test_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,15 @@ def test_radial_gradients_5(assert_pixels):
SzzzzzzzzS
''', '''<style>@page { size: 10px 16px; background:
radial-gradient(red 50%, rgba(255, 0, 0, 0.751) 50%)''')


@assert_no_logs
def test_linear_gradients_currentcolor(assert_pixels):
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1561
assert_pixels('''
KKKKK
KKKKK
KKKKK
KKKKK
KKKKK
''', '<style>@page { size: 5px 5px; background: linear-gradient(currentcolor)')
2 changes: 1 addition & 1 deletion weasyprint/css/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def parse_radial_gradient_parameters(arguments):
def parse_color_stop(tokens):
if len(tokens) == 1:
color = parse_color(tokens[0])
if color == 'currentColor':
if color == 'currentcolor':
# TODO: return the current color instead
return parse_color('black'), None
if color is not None:
Expand Down

0 comments on commit db288a4

Please sign in to comment.