diff --git a/tests/test_css_descriptors.py b/tests/test_css_descriptors.py index b0998174..56e1e402 100644 --- a/tests/test_css_descriptors.py +++ b/tests/test_css_descriptors.py @@ -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 {' diff --git a/weasyprint/css/validation/descriptors.py b/weasyprint/css/validation/descriptors.py index a80717dd..b61a6e0a 100644 --- a/weasyprint/css/validation/descriptors.py +++ b/weasyprint/css/validation/descriptors.py @@ -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]