From c1178a559ca1cf566211bb712fc0e0c42e26b019 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Wed, 2 Mar 2022 20:57:26 +0100 Subject: [PATCH] Fix (and test) discarded text-align values Fix #1586. --- tests/test_css_validation.py | 26 ++++++++++++++++++++++++++ weasyprint/css/validation/expanders.py | 9 ++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/test_css_validation.py b/tests/test_css_validation.py index 27e588bda..fb71c0ae0 100644 --- a/tests/test_css_validation.py +++ b/tests/test_css_validation.py @@ -1143,3 +1143,29 @@ def test_line_clamp(rule, result): )) def test_line_clamp_invalid(rule, reason): assert_invalid(rule, reason) + + +@assert_no_logs +@pytest.mark.parametrize('rule, result', ( + ('text-align: left', { + 'text_align_all': 'left', 'text_align_last': 'left'}), + ('text-align: end', { + 'text_align_all': 'end', 'text_align_last': 'end'}), + ('text-align: justify', { + 'text_align_all': 'justify', 'text_align_last': 'start'}), + ('text-align: justify-all', { + 'text_align_all': 'justify', 'text_align_last': 'justify'}))) +def test_text_align(rule, result): + assert expand_to_dict(rule) == result + + +@assert_no_logs +@pytest.mark.parametrize('rule, reason', ( + ('text-align: none', 'invalid'), + ('text-align: left left', 'invalid'), + ('text-align: top', 'invalid'), + ('text-align: "right"', 'invalid'), + ('text-align: 1px', 'invalid'), +)) +def test_text_align_invalid(rule, reason): + assert_invalid(rule, reason) diff --git a/weasyprint/css/validation/expanders.py b/weasyprint/css/validation/expanders.py index 98770cf9a..27bddc0a1 100644 --- a/weasyprint/css/validation/expanders.py +++ b/weasyprint/css/validation/expanders.py @@ -21,7 +21,7 @@ flex_grow_shrink, flex_wrap, font_family, font_size, font_stretch, font_style, font_weight, line_height, list_style_image, list_style_position, list_style_type, other_colors, overflow_wrap, - validate_non_shorthand) + text_align_all, validate_non_shorthand) EXPANDERS = {} @@ -648,9 +648,12 @@ def expand_text_align(base_url, name, tokens): keyword = get_single_keyword(tokens) if keyword is None: raise InvalidValues - align_all = 'justify' if keyword == 'justify-all' else keyword - yield 'text_align_all', align_all + align_all = ( + 'justify' if keyword == 'justify-all' else text_align_all(tokens)) + if align_all is None: + raise InvalidValues align_last = 'start' if keyword == 'justify' else align_all + yield 'text_align_all', align_all yield 'text_align_last', align_last else: raise InvalidValues