diff --git a/tests/test_css_validation.py b/tests/test_css_validation.py index 351c99f51..723b6b21a 100644 --- a/tests/test_css_validation.py +++ b/tests/test_css_validation.py @@ -8,6 +8,8 @@ from weasyprint.css import preprocess_declarations from weasyprint.css.computed_values import ZERO_PIXELS from weasyprint.css.properties import INITIAL_VALUES +from weasyprint.css.validation.expanders import EXPANDERS +from weasyprint.css.validation.properties import PROPERTIES from weasyprint.images import LinearGradient, RadialGradient from .testing_utils import assert_no_logs, capture_logs @@ -1248,3 +1250,10 @@ def test_image_orientation(rule, result): )) def test_image_orientation_invalid(rule, reason): assert_invalid(rule, reason) + + +@assert_no_logs +#@pytest.mark.parametrize('expander', list(EXPANDERS) + list(PROPERTIES)) +@pytest.mark.parametrize('expander', list(EXPANDERS)) +def test_empty_value(expander): + assert_invalid(f'{expander}:', message='Ignored') diff --git a/weasyprint/css/validation/__init__.py b/weasyprint/css/validation/__init__.py index cb187cff5..00582840d 100644 --- a/weasyprint/css/validation/__init__.py +++ b/weasyprint/css/validation/__init__.py @@ -169,6 +169,10 @@ def validation_error(level, reason): expander_ = EXPANDERS.get(name, validate_non_shorthand) tokens = remove_whitespace(declaration.value) try: + # Having no tokens is allowed by grammar but refused by all + # properties and expanders. + if not tokens: + raise InvalidValues('no value') # Use list() to consume generators now and catch any error. result = list(expander_(name, tokens, base_url)) except InvalidValues as exc: