Skip to content

Commit

Permalink
minifiers: Fixx CSS2 color code handling
Browse files Browse the repository at this point in the history
Fixes #5506
  • Loading branch information
bep committed Dec 7, 2018
1 parent 931a132 commit 4b5f743
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion minifiers/minifiers.go
Expand Up @@ -71,8 +71,13 @@ func New(mediaTypes media.Types, outputFormats output.Formats) Client {
KeepDefaultAttrVals: true,
}

cssMin := &css.Minifier{
Decimals: -1,
KeepCSS2: true,
}

// We use the Type definition of the media types defined in the site if found.
addMinifierFunc(m, mediaTypes, "css", css.Minify)
addMinifier(m, mediaTypes, "css", cssMin)
addMinifierFunc(m, mediaTypes, "js", js.Minify)
m.AddFuncRegexp(regexp.MustCompile("^(application|text)/(x-)?(java|ecma)script$"), js.Minify)
m.AddFuncRegexp(regexp.MustCompile("^(application|text)/(x-|ld\\+)?json$"), json.Minify)
Expand Down
20 changes: 20 additions & 0 deletions minifiers/minifiers_test.go
Expand Up @@ -71,3 +71,23 @@ func TestNew(t *testing.T) {
}

}

func TestBugs(t *testing.T) {
assert := require.New(t)
m := New(media.DefaultTypes, output.DefaultFormats)

for _, test := range []struct {
tp media.Type
rawString string
expectedMinString string
}{
// https://github.com/gohugoio/hugo/issues/5506
{media.CSSType, " body { color: rgba(000, 000, 000, 0.7); }", "body{color:rgba(0,0,0,.7)}"},
} {
var b bytes.Buffer

assert.NoError(m.Minify(test.tp, &b, strings.NewReader(test.rawString)))
assert.Equal(test.expectedMinString, b.String())
}

}

0 comments on commit 4b5f743

Please sign in to comment.