Repository: w3c/epubcheck (java)

Issue:
Empty CSS custom values generate an error
Hello I'm also running with an issue similar to the one describe here

https://github.com/twbs/bootstrap/issues/38061

when including part of the boostrap css in an epub V3 file as epubcheck is reporting an error on empty value for custom css properties. After verification I agree with the boostrap team that it is legal CSS for custom properties to be empty whereas it is not legal for regular properties to be empty and it seems it is a bug in epubcheck to report this as an error. 

To replicate the error simply take the boostrap CSS here

https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.css

and include it in an epub3 file, then run epubcheck vs 5.0.1 and you will get an error like this:

ERROR(CSS-008): ../untitled.epub/OEBPS/Styles/main.css(2731,25): An error occurred while parsing the CSS: Token ";" not allowed here, expecting a property value.


Pull request description:
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

Patch:
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 1dc9bb7a..4d9a8af2 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 @@ public final class CssParser
         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")));


Test patch:
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 2c9b5692..63d241b0 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 class CssParserTest {
     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 55a9e719..eb69d257 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 {