Fix shortcode name in error message on self-closing shortcodes with no .Inner

Fixes #13344
This commit is contained in:
Bjørn Erik Pedersen 2025-02-04 11:18:26 +01:00
parent 377287a614
commit e865d59844
2 changed files with 28 additions and 8 deletions

View file

@ -650,7 +650,11 @@ Loop:
// return that error, more specific // return that error, more specific
continue continue
} }
return nil, fmt.Errorf("%s: shortcode %q does not evaluate .Inner or .InnerDeindent, yet a closing tag was provided", errorPrefix, next.ValStr(source)) name := sc.name
if name == "" {
name = next.ValStr(source)
}
return nil, fmt.Errorf("%s: shortcode %q does not evaluate .Inner or .InnerDeindent, yet a closing tag was provided", errorPrefix, name)
} }
} }
if next.IsRightShortcodeDelim() { if next.IsRightShortcodeDelim() {

View file

@ -831,19 +831,35 @@ title: "Hugo Rocks!"
func TestShortcodeNoInner(t *testing.T) { func TestShortcodeNoInner(t *testing.T) {
t.Parallel() t.Parallel()
b := newTestSitesBuilder(t) files := `
-- hugo.toml --
b.WithContent("mypage.md", `--- baseURL = "https://example.org"
disableKinds = ["term", "taxonomy", "home", "section"]
-- content/mypage.md --
---
title: "No Inner!" title: "No Inner!"
--- ---
{{< noinner >}}{{< /noinner >}} {{< noinner >}}{{< /noinner >}}
-- layouts/shortcodes/noinner.html --
No inner here.
-- layouts/_default/single.html --
Content: {{ .Content }}|
`).WithTemplatesAdded( `
"layouts/shortcodes/noinner.html", `No inner here.`)
err := b.BuildE(BuildCfg{}) b, err := TestE(t, files)
b.Assert(err.Error(), qt.Contains, filepath.FromSlash(`"content/mypage.md:4:16": failed to extract shortcode: shortcode "noinner" does not evaluate .Inner or .InnerDeindent, yet a closing tag was provided`))
assert := func() {
b.Assert(err.Error(), qt.Contains, filepath.FromSlash(`failed to extract shortcode: shortcode "noinner" does not evaluate .Inner or .InnerDeindent, yet a closing tag was provided`))
}
assert()
b, err = TestE(t, strings.Replace(files, `{{< noinner >}}{{< /noinner >}}`, `{{< noinner />}}`, 1))
assert()
} }
func TestShortcodeStableOutputFormatTemplates(t *testing.T) { func TestShortcodeStableOutputFormatTemplates(t *testing.T) {