Skip to content

Commit e865d59

Browse files
committed
Fix shortcode name in error message on self-closing shortcodes with no .Inner
Fixes #13344
1 parent 377287a commit e865d59

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

hugolib/shortcode.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,11 @@ Loop:
650650
// return that error, more specific
651651
continue
652652
}
653-
return nil, fmt.Errorf("%s: shortcode %q does not evaluate .Inner or .InnerDeindent, yet a closing tag was provided", errorPrefix, next.ValStr(source))
653+
name := sc.name
654+
if name == "" {
655+
name = next.ValStr(source)
656+
}
657+
return nil, fmt.Errorf("%s: shortcode %q does not evaluate .Inner or .InnerDeindent, yet a closing tag was provided", errorPrefix, name)
654658
}
655659
}
656660
if next.IsRightShortcodeDelim() {

hugolib/shortcode_test.go

+23-7
Original file line numberDiff line numberDiff line change
@@ -831,19 +831,35 @@ title: "Hugo Rocks!"
831831
func TestShortcodeNoInner(t *testing.T) {
832832
t.Parallel()
833833

834-
b := newTestSitesBuilder(t)
835-
836-
b.WithContent("mypage.md", `---
834+
files := `
835+
-- hugo.toml --
836+
baseURL = "https://example.org"
837+
disableKinds = ["term", "taxonomy", "home", "section"]
838+
-- content/mypage.md --
839+
---
837840
title: "No Inner!"
838841
---
842+
839843
{{< noinner >}}{{< /noinner >}}
840844
845+
-- layouts/shortcodes/noinner.html --
846+
No inner here.
847+
-- layouts/_default/single.html --
848+
Content: {{ .Content }}|
841849
842-
`).WithTemplatesAdded(
843-
"layouts/shortcodes/noinner.html", `No inner here.`)
850+
`
851+
852+
b, err := TestE(t, files)
853+
854+
assert := func() {
855+
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`))
856+
}
844857

845-
err := b.BuildE(BuildCfg{})
846-
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`))
858+
assert()
859+
860+
b, err = TestE(t, strings.Replace(files, `{{< noinner >}}{{< /noinner >}}`, `{{< noinner />}}`, 1))
861+
862+
assert()
847863
}
848864

849865
func TestShortcodeStableOutputFormatTemplates(t *testing.T) {

0 commit comments

Comments
 (0)