postcss: Fix no-map vs noMap discrepancy

Fixes #6166
This commit is contained in:
Bjørn Erik Pedersen 2019-08-05 13:48:58 +02:00
parent de87624241
commit 02397e76ce
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
2 changed files with 50 additions and 1 deletions

View file

@ -17,6 +17,8 @@ import (
"io"
"path/filepath"
"github.com/spf13/cast"
"github.com/gohugoio/hugo/hugofs"
"github.com/pkg/errors"
@ -36,7 +38,7 @@ type Options struct {
// Set a custom path to look for a config file.
Config string
NoMap bool `mapstructure:"no-map"` // Disable the default inline sourcemaps
NoMap bool // Disable the default inline sourcemaps
// Options for when not using a config file
Use string // List of postcss plugins to use
@ -50,6 +52,14 @@ func DecodeOptions(m map[string]interface{}) (opts Options, err error) {
return
}
err = mapstructure.WeakDecode(m, &opts)
if !opts.NoMap {
// There was for a long time a disrepency between documentation and
// implementation for the noMap property, so we need to support both
// camel and snake case.
opts.NoMap = cast.ToBool(m["no-map"])
}
return
}

View file

@ -0,0 +1,39 @@
// Copyright 2020 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package postcss
import (
"testing"
"github.com/stretchr/testify/require"
)
// Issue 6166
func TestDecodeOptions(t *testing.T) {
assert := require.New(t)
opts1, err := DecodeOptions(map[string]interface{}{
"no-map": true,
})
assert.NoError(err)
assert.True(opts1.NoMap)
opts2, err := DecodeOptions(map[string]interface{}{
"noMap": true,
})
assert.NoError(err)
assert.True(opts2.NoMap)
}