Skip to content

Commit

Permalink
CSS: distinguish between empty and whitespace in custom variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jun 12, 2020
1 parent 6a0abc1 commit 0ff4e9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion css/css.go
Expand Up @@ -245,7 +245,11 @@ func (c *cssMinifier) minifyGrammar() error {
if _, err := c.w.Write(colonBytes); err != nil {
return err
}
if _, err := c.w.Write(parse.TrimWhitespace(c.p.Values()[0].Data)); err != nil {
value := parse.TrimWhitespace(c.p.Values()[0].Data)
if len(c.p.Values()[0].Data) != 0 && len(value) == 0 {
value = spaceBytes
}
if _, err := c.w.Write(value); err != nil {
return err
}
semicolonQueued = true
Expand Down
3 changes: 2 additions & 1 deletion css/css_test.go
Expand Up @@ -304,7 +304,8 @@ func TestCSSInline(t *testing.T) {
{"--custom-variable:0px;", "--custom-variable:0px"},
{"--foo: 0px ;", "--foo:0px"},
{"--foo: if(x > 5) this.width = 10", "--foo:if(x > 5) this.width = 10"},
{"--foo: ;", "--foo:"}, // empty value
{"--foo: ;", "--foo: "}, // whitespace value
{"--foo:;", "--foo:"}, // empty value
{"--foo: initial ;", "--foo:initial"}, // invalid value, serializes to empty
{"color=blue;", "color=blue"},
{"x: white , white", "x:white,white"},
Expand Down

0 comments on commit 0ff4e9c

Please sign in to comment.