Skip to content

Commit

Permalink
fix: allow CSS custom properties with no value
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rdeltour committed Dec 23, 2024
1 parent 90e87b2 commit d60da30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/idpf/epubcheck/util/css/CssParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/idpf/epubcheck/util/css/CssParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/css/custom-properties.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

:root {
--main-bg-color: brown;
--empty:;
}

.one {
Expand Down

0 comments on commit d60da30

Please sign in to comment.