Skip to content

Commit

Permalink
Bugfix: early string ending for font-family
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 15, 2015
1 parent ce19332 commit ebea09e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 14 additions & 9 deletions css/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,19 @@ func (c *cssMinifier) minifyDeclaration(property []byte, values []css.Token) err
values[i].TokenType = css.NumberToken
values[i].Data = []byte("700")
}
} else if value.TokenType == css.StringToken && (prop == css.Font || prop == css.Font_Family) {
} else if value.TokenType == css.StringToken && (prop == css.Font || prop == css.Font_Family) && len(value.Data) > 2 {
unquote := true
parse.ToLower(value.Data)
s := value.Data[1 : len(value.Data)-1]
unquote := true
for _, split := range bytes.Split(s, spaceBytes) {
val := css.ToHash(split)
// if len is zero, it contains two consecutive spaces
if val == css.Inherit || val == css.Serif || val == css.Sans_Serif || val == css.Monospace || val == css.Fantasy || val == css.Cursive || val == css.Initial || val == css.Default ||
len(split) == 0 || !css.IsIdent(split) {
unquote = false
break
if len(s) > 0 {
for _, split := range bytes.Split(s, spaceBytes) {
val := css.ToHash(split)
// if len is zero, it contains two consecutive spaces
if val == css.Inherit || val == css.Serif || val == css.Sans_Serif || val == css.Monospace || val == css.Fantasy || val == css.Cursive || val == css.Initial || val == css.Default ||
len(split) == 0 || !css.IsIdent(split) {
unquote = false
break
}
}
}
if unquote {
Expand Down Expand Up @@ -425,6 +427,9 @@ func (c *cssMinifier) shortenToken(tt css.TokenType, data []byte) (css.TokenType
break
}
}
if len(data) < 3 {
data = data[:0]
}
} else if tt == css.URLToken {
parse.ToLower(data[:3])
if len(data) > 10 {
Expand Down
4 changes: 4 additions & 0 deletions css/css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestCSS(t *testing.T) {
assertCSS(t, m, false, "filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);", "filter:alpha(opacity=0)")
assertCSS(t, m, false, "content: \"a\\\nb\";", "content:\"ab\"")
assertCSS(t, m, false, "content: \"a\\\r\nb\\\r\nc\";", "content:\"abc\"")
assertCSS(t, m, false, "content: \"\";", "content:")
assertCSS(t, m, true, "i { key: value; key2: value; }", "i{key:value;key2:value}")
assertCSS(t, m, true, ".cla .ss > #id { x:y; }", ".cla .ss>#id{x:y}")
assertCSS(t, m, true, ".cla[id ^= L] { x:y; }", ".cla[id^=L]{x:y}")
Expand Down Expand Up @@ -116,6 +117,9 @@ func TestCSS(t *testing.T) {
assertCSS(t, m, false, "margin: rgb(ident);", "margin:rgb(ident)")
assertCSS(t, m, false, "filter: progid:b().c.Alpha(rgba(x));", "filter:progid:b().c.Alpha(rgba(x))")
assertCSS(t, m, true, "a, b + c { x:y; }", "a,b+c{x:y}")

// go-fuzz
assertCSS(t, m, false, "FONT-FAMILY: ru\"", "font-family:ru")
}

////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit ebea09e

Please sign in to comment.