diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-12-07 07:49:26 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-12-07 07:49:26 +0100 |
commit | 4b5f743959394d443c4dcaa0ccae21842b51adaf (patch) | |
tree | ae9f5604d9d804b4bbc04a64bbfc5bfeae161201 /minifiers | |
parent | 931a1324503a4414e38d26efe82e1add811a8d29 (diff) | |
download | hugo-4b5f743959394d443c4dcaa0ccae21842b51adaf.tar.gz hugo-4b5f743959394d443c4dcaa0ccae21842b51adaf.zip |
minifiers: Fixx CSS2 color code handling
Fixes #5506
Diffstat (limited to 'minifiers')
-rw-r--r-- | minifiers/minifiers.go | 7 | ||||
-rw-r--r-- | minifiers/minifiers_test.go | 20 |
2 files changed, 26 insertions, 1 deletions
diff --git a/minifiers/minifiers.go b/minifiers/minifiers.go index 8a9730a73..db2251b68 100644 --- a/minifiers/minifiers.go +++ b/minifiers/minifiers.go @@ -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) diff --git a/minifiers/minifiers_test.go b/minifiers/minifiers_test.go index 6500aa2c2..acfa22d2c 100644 --- a/minifiers/minifiers_test.go +++ b/minifiers/minifiers_test.go @@ -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()) + } + +} |