minifiers: Fixx CSS2 color code handling

Fixes #5506
This commit is contained in:
Bjørn Erik Pedersen committed 2018-12-07 07:49:26 +01:00
1 parent 931a132450
commit 4b5f743959
2 files changed
+26 -1

No files matched your search

+6 -1
View File
@@ -71,8 +71,13 @@ func New(mediaTypes media.Types, outputFormats output.Formats) Client {
KeepDefaultAttrVals: true, KeepDefaultAttrVals: true,
} }
cssMin := &css.Minifier{
Decimals: -1,
KeepCSS2: true,
}
// We use the Type definition of the media types defined in the site if found. // 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) 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-)?(java|ecma)script$"), js.Minify)
m.AddFuncRegexp(regexp.MustCompile("^(application|text)/(x-|ld\\+)?json$"), json.Minify) m.AddFuncRegexp(regexp.MustCompile("^(application|text)/(x-|ld\\+)?json$"), json.Minify)
+20
View File
@@ -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())
}
}