Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-05 14:48:58 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-05 14:48:58 +0300
commit02397e76cece28b467de30ff0cb0f471d9b212ee (patch)
tree66007e6ad3dc99db277e430c062fa4116f591c14 /resources
parentde87624241daa86660f205cc72a745409b9c9238 (diff)
postcss: Fix no-map vs noMap discrepancy
Fixes #6166
Diffstat (limited to 'resources')
-rw-r--r--resources/resource_transformers/postcss/postcss.go12
-rw-r--r--resources/resource_transformers/postcss/postcss_test.go39
2 files changed, 50 insertions, 1 deletions
diff --git a/resources/resource_transformers/postcss/postcss.go b/resources/resource_transformers/postcss/postcss.go
index 125989a10..8185c5a23 100644
--- a/resources/resource_transformers/postcss/postcss.go
+++ b/resources/resource_transformers/postcss/postcss.go
@@ -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
}
diff --git a/resources/resource_transformers/postcss/postcss_test.go b/resources/resource_transformers/postcss/postcss_test.go
new file mode 100644
index 000000000..b6b365f32
--- /dev/null
+++ b/resources/resource_transformers/postcss/postcss_test.go
@@ -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)
+
+}