Skip to content

Commit

Permalink
Add CustomProperty parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Mar 25, 2017
1 parent 6206d45 commit 5d60bd9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 11 additions & 0 deletions css/css.go
Expand Up @@ -131,6 +131,17 @@ func (c *cssMinifier) minifyGrammar() error {
return err
}
semicolonQueued = true
} else if gt == css.CustomPropertyGrammar {
if _, err := c.w.Write(data); err != nil {
return err
}
if _, err := c.w.Write(colonBytes); err != nil {
return err
}
if _, err := c.w.Write(c.p.Values()[0].Data); err != nil {
return err
}
semicolonQueued = true
} else if gt == css.CommentGrammar {
if len(data) > 5 && data[1] == '*' && data[2] == '!' {
if _, err := c.w.Write(data[:3]); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions css/css_test.go
Expand Up @@ -34,14 +34,16 @@ func TestCSS(t *testing.T) {
{"html{line-height:1;}html{line-height:1;}", "html{line-height:1}html{line-height:1}"},
{"a { b: 1", "a{b:1}"},

{":root { --custom-variable:0px; }", ":root{--custom-variable:0px}"},

// case sensitivity
{"@counter-style Ident{}", "@counter-style Ident{}"},

// coverage
{"a, b + c { x:y; }", "a,b+c{x:y}"},

// bad declaration
{".clearfix { *zoom: 1; }", ".clearfix{*zoom:1}"},
{".clearfix { *zoom: 1px; }", ".clearfix{*zoom:1px}"},

// go-fuzz
{"input[type=\"\x00\"] { a: b\n}.a{}", "input[type=\"\x00\"]{a:b}.a{}"},
Expand Down Expand Up @@ -133,6 +135,9 @@ func TestCSSInline(t *testing.T) {
{"z-index:1000", "z-index:1000"},

{"any:0deg 0s 0ms 0dpi 0dpcm 0dppx 0hz 0khz", "any:0 0s 0ms 0dpi 0dpcm 0dppx 0hz 0khz"},
{"--custom-variable:0px;", "--custom-variable:0px"},
{"--foo: if(x > 5) this.width = 10", "--foo: if(x > 5) this.width = 10"},
{"--foo: ;", "--foo: "},

// case sensitivity
{"animation:Ident", "animation:Ident"},
Expand All @@ -153,9 +158,6 @@ func TestCSSInline(t *testing.T) {
{"margin: rgb(ident);", "margin:rgb(ident)"},
{"filter: progid:b().c.Alpha(rgba(x));", "filter:progid:b().c.Alpha(rgba(x))"},

// bad declaration
{"--bad-ident:0", "--bad-ident:0"},

// go-fuzz
{"FONT-FAMILY: ru\"", "font-family:ru\""},
}
Expand Down

0 comments on commit 5d60bd9

Please sign in to comment.