Skip to content

Commit d60da30

Browse files
committed
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
1 parent 90e87b2 commit d60da30

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/main/java/org/idpf/epubcheck/util/css/CssParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ private CssDeclaration handleDeclaration(CssToken name, CssTokenIterator iter,
373373
CssToken value = iter.next();
374374
if (MATCH_SEMI_CLOSEBRACE.apply(value))
375375
{
376-
if (declaration.components.size() < 1)
376+
if (declaration.components.size() < 1 && !declaration.name.or("").startsWith("--"))
377377
{
378378
err.error(new CssGrammarException(GRAMMAR_EXPECTING_TOKEN, iter.last.location,
379379
messages.getLocale(), value.getChar(), messages.get("a_property_value")));

src/test/java/org/idpf/epubcheck/util/css/CssParserTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ public void testParser015() throws Exception {
178178
HandlerImpl handler = checkBasics(exec(s));
179179
assertEquals(0, handler.errors.size());
180180
}
181+
182+
@Test
183+
public void testParser016() throws Exception {
184+
String s = "E { --my-property: ; } ";
185+
HandlerImpl handler = checkBasics(exec(s));
186+
assertEquals(0, handler.errors.size());
187+
}
181188

182189
@Test
183190
public void testParserAtRule001() throws Exception {

src/test/resources/css/custom-properties.css

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
:root {
66
--main-bg-color: brown;
7+
--empty:;
78
}
89

910
.one {

0 commit comments

Comments
 (0)