hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 311b8008bfba3411741ef8ebe4b094adb92ce041
parent c7d5f9f067fd6a37ac6b75cb1c02259debd3ff21
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Sat,  4 Jun 2022 17:39:34 +0200

helpers: Fix panic with invalid defaultMarkdownHandler

Fixes #9968

Diffstat:
Mhugolib/config_test.go | 26++++++++++++++++++++++++++
Mhugolib/integrationtest_builder.go | 15++++++++++++---
Mmarkup/markup.go | 14+++++++++++++-
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git 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
@@ -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
@@ -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,