shithub: hugo

Download patch

ref: 02397e76cece28b467de30ff0cb0f471d9b212ee
parent: de87624241daa86660f205cc72a745409b9c9238
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Mon Aug 5 09:48:58 EDT 2019

postcss: Fix no-map vs noMap discrepancy

Fixes #6166

--- a/resources/resource_transformers/postcss/postcss.go
+++ b/resources/resource_transformers/postcss/postcss.go
@@ -17,6 +17,8 @@
 	"io"
 	"path/filepath"
 
+	"github.com/spf13/cast"
+
 	"github.com/gohugoio/hugo/hugofs"
 	"github.com/pkg/errors"
 
@@ -36,7 +38,7 @@
 	// 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 @@
 		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
 }
 
--- /dev/null
+++ b/resources/resource_transformers/postcss/postcss_test.go
@@ -1,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)
+
+}