diff options
author | Joe Mooring <[email protected]> | 2021-11-30 13:39:47 -0800 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-12-01 10:17:42 +0100 |
commit | f122771fb1345786f81011181cfd2c452f316278 (patch) | |
tree | 01a671a69502d6eb375bd017e084d24cf579ddc0 | |
parent | 08a863e1e8c7761253939bbafdfdfb9d67df266c (diff) | |
download | hugo-f122771fb1345786f81011181cfd2c452f316278.tar.gz hugo-f122771fb1345786f81011181cfd2c452f316278.zip |
Check for empty deployment targets and matchers
Fixes #9220
-rw-r--r-- | deploy/deployConfig.go | 8 | ||||
-rw-r--r-- | deploy/deployConfig_test.go | 32 |
2 files changed, 39 insertions, 1 deletions
diff --git a/deploy/deployConfig.go b/deploy/deployConfig.go index 443c5901a..e2413a6c0 100644 --- a/deploy/deployConfig.go +++ b/deploy/deployConfig.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !nodeploy // +build !nodeploy package deploy @@ -24,6 +25,7 @@ import ( hglob "github.com/gohugoio/hugo/hugofs/glob" "github.com/gohugoio/hugo/media" "github.com/mitchellh/mapstructure" + "github.com/pkg/errors" ) const deploymentConfigKey = "deployment" @@ -124,12 +126,18 @@ func decodeConfig(cfg config.Provider) (deployConfig, error) { return dcfg, err } for _, tgt := range dcfg.Targets { + if tgt == nil { + return dcfg, errors.New("empty deployment target") + } if err := tgt.parseIncludeExclude(); err != nil { return dcfg, err } } var err error for _, m := range dcfg.Matchers { + if m == nil { + return dcfg, errors.New("empty deployment matcher") + } m.re, err = regexp.Compile(m.Pattern) if err != nil { return dcfg, fmt.Errorf("invalid deployment.matchers.pattern: %v", err) diff --git a/deploy/deployConfig_test.go b/deploy/deployConfig_test.go index e30f31c32..091ebdb2e 100644 --- a/deploy/deployConfig_test.go +++ b/deploy/deployConfig_test.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !nodeploy // +build !nodeploy package deploy @@ -21,7 +22,6 @@ import ( qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/config" - ) func TestDecodeConfigFromTOML(t *testing.T) { @@ -169,3 +169,33 @@ func TestDecodeConfigDefault(t *testing.T) { c.Assert(len(dcfg.Targets), qt.Equals, 0) c.Assert(len(dcfg.Matchers), qt.Equals, 0) } + +func TestEmptyTarget(t *testing.T) { + c := qt.New(t) + + tomlConfig := ` +[deployment] +[[deployment.targets]] +` + cfg, err := config.FromConfigString(tomlConfig, "toml") + c.Assert(err, qt.IsNil) + + _, err = decodeConfig(cfg) + c.Assert(err, qt.Not(qt.IsNil)) +} + +func TestEmptyMatcher(t *testing.T) { + c := qt.New(t) + + tomlConfig := ` +[deployment] +[[deployment.matchers]] +` + cfg, err := config.FromConfigString(tomlConfig, "toml") + c.Assert(err, qt.IsNil) + + _, err = decodeConfig(cfg) + c.Assert(err, qt.Not(qt.IsNil)) + + fmt.Printf("JMM-1: %s", err) +} |