Detect now invalid path patterns in cascade

Closes #11977
This commit is contained in:
Bjørn Erik Pedersen
2024-02-03 13:09:53 +01:00
parent a66480f70c
commit 058f230a1b
7 changed files with 72 additions and 15 deletions

View File

@@ -671,3 +671,32 @@ S1|p1:|p2:p2|
`)
})
}
// Issue 11977.
func TestCascadeExtensionInPath(t *testing.T) {
files := `
-- hugo.toml --
baseURL = "https://example.org"
[languages]
[languages.en]
weight = 1
[languages.de]
-- content/_index.de.md --
+++
[[cascade]]
[cascade.params]
foo = 'bar'
[cascade._target]
path = '/posts/post-1.de.md'
+++
-- content/posts/post-1.de.md --
---
title: "Post 1"
---
-- layouts/_default/single.html --
{{ .Title }}|{{ .Params.foo }}$
`
b, err := TestE(t, files)
b.Assert(err, qt.IsNotNil)
b.AssertLogContains(`cascade target path "/posts/post-1.de.md" looks like a path with an extension; since Hugo v0.123.0 this will not match anything, see https://gohugo.io/methods/page/path/`)
}

View File

@@ -33,6 +33,7 @@ import (
"github.com/gohugoio/hugo/common/constants"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/config"
@@ -272,7 +273,7 @@ func (p *pageMeta) Weight() int {
return p.pageConfig.Weight
}
func (p *pageMeta) setMetaPre(pi *contentParseInfo, conf config.AllProvider) error {
func (p *pageMeta) setMetaPre(pi *contentParseInfo, logger loggers.Logger, conf config.AllProvider) error {
frontmatter := pi.frontMatter
if frontmatter != nil {
pcfg := p.pageConfig
@@ -285,7 +286,7 @@ func (p *pageMeta) setMetaPre(pi *contentParseInfo, conf config.AllProvider) err
// Check for any cascade define on itself.
if cv, found := frontmatter["cascade"]; found {
var err error
cascade, err := page.DecodeCascade(cv)
cascade, err := page.DecodeCascade(logger, cv)
if err != nil {
return err
}
@@ -437,7 +438,6 @@ func (p *pageState) setMetaPostParams() error {
}
pm.pageConfig.Build, err = pagemeta.DecodeBuildConfig(buildConfig)
if err != nil {
//lint:ignore ST1005 end user message.
var msgDetail string
if isNewBuildKeyword {
msgDetail = `. We renamed the _build keyword to build in Hugo 0.123.0. We recommend putting user defined params in the params section, e.g.:

View File

@@ -56,7 +56,7 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
return nil, nil, err
}
if err := m.setMetaPre(pi, h.Conf); err != nil {
if err := m.setMetaPre(pi, h.Log, h.Conf); err != nil {
return nil, nil, m.wrapError(err, h.BaseFs.SourceFs)
}
pcfg := m.pageConfig