From d60da300263b92232e1dc418c581e66fdf43f37d Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Fri, 20 Dec 2024 22:54:30 +0100 Subject: [PATCH] fix: allow CSS custom properties with no value Fix the built-in CSS parser to allow custom properties with empty values, as this is valid CSS. See https://www.w3.org/TR/css-variables/#guaranteed-invalid Fixes #1538 --- src/main/java/org/idpf/epubcheck/util/css/CssParser.java | 2 +- .../java/org/idpf/epubcheck/util/css/CssParserTest.java | 7 +++++++ src/test/resources/css/custom-properties.css | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/idpf/epubcheck/util/css/CssParser.java b/src/main/java/org/idpf/epubcheck/util/css/CssParser.java index 1dc9bb7ae..4d9a8af28 100644 --- a/src/main/java/org/idpf/epubcheck/util/css/CssParser.java +++ b/src/main/java/org/idpf/epubcheck/util/css/CssParser.java @@ -373,7 +373,7 @@ private CssDeclaration handleDeclaration(CssToken name, CssTokenIterator iter, CssToken value = iter.next(); if (MATCH_SEMI_CLOSEBRACE.apply(value)) { - if (declaration.components.size() < 1) + if (declaration.components.size() < 1 && !declaration.name.or("").startsWith("--")) { err.error(new CssGrammarException(GRAMMAR_EXPECTING_TOKEN, iter.last.location, messages.getLocale(), value.getChar(), messages.get("a_property_value"))); diff --git a/src/test/java/org/idpf/epubcheck/util/css/CssParserTest.java b/src/test/java/org/idpf/epubcheck/util/css/CssParserTest.java index 2c9b5692d..63d241b0d 100644 --- a/src/test/java/org/idpf/epubcheck/util/css/CssParserTest.java +++ b/src/test/java/org/idpf/epubcheck/util/css/CssParserTest.java @@ -178,6 +178,13 @@ public void testParser015() throws Exception { HandlerImpl handler = checkBasics(exec(s)); assertEquals(0, handler.errors.size()); } + + @Test + public void testParser016() throws Exception { + String s = "E { --my-property: ; } "; + HandlerImpl handler = checkBasics(exec(s)); + assertEquals(0, handler.errors.size()); + } @Test public void testParserAtRule001() throws Exception { diff --git a/src/test/resources/css/custom-properties.css b/src/test/resources/css/custom-properties.css index 55a9e7191..eb69d257f 100644 --- a/src/test/resources/css/custom-properties.css +++ b/src/test/resources/css/custom-properties.css @@ -4,6 +4,7 @@ :root { --main-bg-color: brown; + --empty:; } .one {