diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-06-04 17:39:34 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-06-04 17:47:20 +0200 |
commit | 311b8008bfba3411741ef8ebe4b094adb92ce041 (patch) | |
tree | b79e2023069fd48f5023f0b03b820542ee26dd65 | |
parent | c7d5f9f067fd6a37ac6b75cb1c02259debd3ff21 (diff) | |
download | hugo-311b8008bfba3411741ef8ebe4b094adb92ce041.tar.gz hugo-311b8008bfba3411741ef8ebe4b094adb92ce041.zip |
helpers: Fix panic with invalid defaultMarkdownHandler
Fixes #9968
-rw-r--r-- | hugolib/config_test.go | 26 | ||||
-rw-r--r-- | hugolib/integrationtest_builder.go | 15 | ||||
-rw-r--r-- | markup/markup.go | 14 |
3 files changed, 51 insertions, 4 deletions
diff --git a/hugolib/config_test.go b/hugolib/config_test.go index 222568b7c..882d83c8d 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -756,3 +756,29 @@ theme_param="themevalue2" }) } + +func TestInvalidDefaultMarkdownHandler(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +[markup] +defaultMarkdownHandler = 'blackfriday' +-- content/_index.md -- +## Foo +-- layouts/index.html -- +{{ .Content }} + +` + + b, err := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).BuildE() + + b.Assert(err, qt.IsNotNil) + b.Assert(err.Error(), qt.Contains, "Configured defaultMarkdownHandler \"blackfriday\" not found. Did you mean to use goldmark? Blackfriday was removed in Hugo v0.100.0.") + +} diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go index df51b37c3..9dcfe4830 100644 --- a/hugolib/integrationtest_builder.go +++ b/hugolib/integrationtest_builder.go @@ -197,7 +197,10 @@ func (s *IntegrationTestBuilder) Build() *IntegrationTestBuilder { func (s *IntegrationTestBuilder) BuildE() (*IntegrationTestBuilder, error) { s.Helper() - s.initBuilder() + if err := s.initBuilder(); err != nil { + return s, err + } + err := s.build(BuildCfg{}) return s, err } @@ -267,7 +270,8 @@ func (s *IntegrationTestBuilder) FileContent(filename string) string { return s.readWorkingDir(s, s.fs, filepath.FromSlash(filename)) } -func (s *IntegrationTestBuilder) initBuilder() { +func (s *IntegrationTestBuilder) initBuilder() error { + var initErr error s.builderInit.Do(func() { var afs afero.Fs if s.Cfg.NeedsOsFS { @@ -320,7 +324,10 @@ func (s *IntegrationTestBuilder) initBuilder() { depsCfg := deps.DepsCfg{Cfg: cfg, Fs: fs, Running: s.Cfg.Running, Logger: logger} sites, err := NewHugoSites(depsCfg) - s.Assert(err, qt.IsNil) + if err != nil { + initErr = err + return + } s.H = sites s.fs = fs @@ -338,6 +345,8 @@ func (s *IntegrationTestBuilder) initBuilder() { } }) + + return initErr } func (s *IntegrationTestBuilder) absFilename(filename string) string { diff --git a/markup/markup.go b/markup/markup.go index f5e46ad90..1345867f9 100644 --- a/markup/markup.go +++ b/markup/markup.go @@ -14,6 +14,7 @@ package markup import ( + "fmt" "strings" "github.com/gohugoio/hugo/markup/highlight" @@ -43,6 +44,8 @@ func NewConverterProvider(cfg converter.ProviderConfig) (ConverterProvider, erro } cfg.MarkupConfig = markupConfig + defaultHandler := cfg.MarkupConfig.DefaultMarkdownHandler + var defaultFound bool add := func(p converter.ProviderProvider, aliases ...string) error { c, err := p.New(cfg) @@ -54,8 +57,9 @@ func NewConverterProvider(cfg converter.ProviderConfig) (ConverterProvider, erro aliases = append(aliases, name) - if strings.EqualFold(name, cfg.MarkupConfig.DefaultMarkdownHandler) { + if strings.EqualFold(name, defaultHandler) { aliases = append(aliases, "markdown") + defaultFound = true } addConverter(converters, c, aliases...) @@ -78,6 +82,14 @@ func NewConverterProvider(cfg converter.ProviderConfig) (ConverterProvider, erro return nil, err } + if !defaultFound { + msg := "markup: Configured defaultMarkdownHandler %q not found." + if defaultHandler == "blackfriday" { + msg += " Did you mean to use goldmark? Blackfriday was removed in Hugo v0.100.0." + } + return nil, fmt.Errorf(msg, defaultHandler) + } + return &converterRegistry{ config: cfg, converters: converters, |