Skip to content

Commit

Permalink
Don't allow unknown units during line-height validation (fix #225)
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Apr 28, 2015
1 parent b4c4360 commit 01a5ce7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions weasyprint/css/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,12 @@ def line_height(token):
"""``line-height`` property validation."""
if get_keyword(token) == 'normal':
return 'normal'
if (token.type in ('NUMBER', 'INTEGER', 'DIMENSION', 'PERCENTAGE') and
token.value >= 0):
if token.type in ('NUMBER', 'INTEGER', 'PERCENTAGE') and token.value >= 0:
return Dimension(token.value, token.unit)
elif token.type == 'DIMENSION' and token.value >= 0:
length = get_length(token)
if length:
return length

This comment has been minimized.

Copy link
@SimonSapin

SimonSapin Apr 28, 2015

Member

These three lines can be just return get_length(token)



@validator()
Expand Down
17 changes: 17 additions & 0 deletions weasyprint/tests/test_css_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,23 @@ def test_font():
assert_invalid('font: 12px "Invalid" family')


@assert_no_logs
def test_line_height():
"""Test the ``line-height`` property."""
assert expand_to_dict('line-height: 1px') == {'line_height': (1, 'px')}
assert expand_to_dict('line-height: 1.1%') == {'line_height': (1.1, '%')}
assert expand_to_dict('line-height: 1em') == {'line_height': (1, 'em')}
assert expand_to_dict('line-height: 1') == {'line_height': (1, None)}
assert expand_to_dict('line-height: 1.3') == {'line_height': (1.3, None)}
assert expand_to_dict('line-height: -0') == {'line_height': (0, None)}
assert expand_to_dict('line-height: 0px') == {'line_height': (0, 'px')}
assert_invalid('line-height: 1deg')
assert_invalid('line-height: -1px')
assert_invalid('line-height: -1')
assert_invalid('line-height: -0.5%')
assert_invalid('line-height: 1px 1px')


@assert_no_logs
def test_linear_gradient():
red = (1, 0, 0, 1)
Expand Down

0 comments on commit 01a5ce7

Please sign in to comment.