mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-03 23:48:07 +03:00
Don’t crash when @font-face’s src ends with a comma
That was the only @comma_separated_list function to assume "tokens" is not empty. Fix #1653.
This commit is contained in:
parent
26d5d8264d
commit
e4885f9cff
@ -67,7 +67,7 @@ def test_font_face_3():
|
||||
|
||||
@assert_no_logs
|
||||
def test_font_face_4():
|
||||
# See bug #487
|
||||
# Test regression: https://github.com/Kozea/WeasyPrint/issues/487
|
||||
stylesheet = tinycss2.parse_stylesheet(
|
||||
'@font-face {'
|
||||
' font-family: Gentium Hard;'
|
||||
@ -82,6 +82,27 @@ def test_font_face_4():
|
||||
assert src == ('src', (('local', 'Gentium Hard'),))
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_font_face_5():
|
||||
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1653
|
||||
stylesheet = tinycss2.parse_stylesheet(
|
||||
'@font-face {'
|
||||
' font-family: Gentium Hard;'
|
||||
' src: local(Gentium Hard);'
|
||||
' src: local(Gentium Soft),'
|
||||
'}')
|
||||
at_rule, = stylesheet
|
||||
assert at_rule.at_keyword == 'font-face'
|
||||
with capture_logs() as logs:
|
||||
font_family, src = list(preprocess_descriptors(
|
||||
'font-face', 'http://weasyprint.org/foo/',
|
||||
tinycss2.parse_declaration_list(at_rule.content)))
|
||||
assert font_family == ('font_family', 'Gentium Hard')
|
||||
assert src == ('src', (('local', 'Gentium Hard'),))
|
||||
assert len(logs) == 1
|
||||
assert 'invalid value' in logs[0]
|
||||
|
||||
|
||||
def test_font_face_bad_1():
|
||||
stylesheet = tinycss2.parse_stylesheet(
|
||||
'@font-face {'
|
||||
|
@ -141,7 +141,7 @@ def font_family(tokens, allow_spaces=False):
|
||||
@comma_separated_list
|
||||
def src(tokens, base_url):
|
||||
"""``src`` descriptor validation."""
|
||||
if len(tokens) <= 2:
|
||||
if len(tokens) in (1, 2):
|
||||
tokens, token = tokens[:-1], tokens[-1]
|
||||
if token.type == 'function' and token.lower_name == 'format':
|
||||
tokens, token = tokens[:-1], tokens[-1]
|
||||
|
Loading…
Reference in New Issue
Block a user