Skip to content

Commit

Permalink
CSS: kepe integers for z-index even in functions such as calc, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Apr 2, 2021
1 parent de33a3b commit b08e2f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions css/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (c *cssMinifier) minifyDeclaration(property []byte, components []css.Token)
return
}

values = c.minifyTokens(prop, values)
values = c.minifyTokens(prop, 0, values)
if len(values) > 0 {
values = c.minifyProperty(prop, values)
}
Expand Down Expand Up @@ -440,7 +440,7 @@ func (c *cssMinifier) writeDeclaration(values []Token, important bool) {
}
}

func (c *cssMinifier) minifyTokens(prop Hash, values []Token) []Token {
func (c *cssMinifier) minifyTokens(prop Hash, fun Hash, values []Token) []Token {
for i, value := range values {
tt := value.TokenType
switch tt {
Expand All @@ -464,7 +464,7 @@ func (c *cssMinifier) minifyTokens(prop Hash, values []Token) []Token {
case css.DimensionToken:
var dim []byte
values[i], dim = c.minifyDimension(values[i])
if 1 < len(values[i].Data) && values[i].Data[0] == '0' && optionalZeroDimension[string(dim)] && prop != Flex && prop != Function {
if 1 < len(values[i].Data) && values[i].Data[0] == '0' && optionalZeroDimension[string(dim)] && prop != Flex && fun == 0 {
// cut dimension for zero value, TODO: don't hardcode check for Flex and remove the dimension in minifyDimension
values[i].Data = values[i].Data[:1]
}
Expand All @@ -489,7 +489,7 @@ func (c *cssMinifier) minifyTokens(prop Hash, values []Token) []Token {
}
}
case css.FunctionToken:
values[i].Args = c.minifyTokens(Function, values[i].Args)
values[i].Args = c.minifyTokens(prop, values[i].Fun, values[i].Args)

fun := values[i].Fun
args := values[i].Args
Expand Down
1 change: 1 addition & 0 deletions css/css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func TestCSSInline(t *testing.T) {
{"background:url('data:\\'\",text')", "background:url('data:\\'\",text')"},
{"margin:0 0 18px 0;", "margin:0 0 18px"},
{"z-index:1000", "z-index:1000"},
{"z-index:calc(1000)", "z-index:calc(1000)"},
//{"flex:0px", "flex:0q"}, // TODO
{"g:url('abc\\\ndef')", "g:url(abcdef)"},
{"url:local('abc\\\ndef')", "url:local(abcdef)"},
Expand Down

0 comments on commit b08e2f4

Please sign in to comment.