Fix shortcode name in error message on self-closing shortcodes with no .Inner
Fixes #13344
This commit is contained in:
parent
377287a614
commit
e865d59844
2 changed files with 28 additions and 8 deletions
|
@ -650,7 +650,11 @@ Loop:
|
|||
// return that error, more specific
|
||||
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() {
|
||||
|
|
|
@ -831,19 +831,35 @@ title: "Hugo Rocks!"
|
|||
func TestShortcodeNoInner(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
b := newTestSitesBuilder(t)
|
||||
|
||||
b.WithContent("mypage.md", `---
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org"
|
||||
disableKinds = ["term", "taxonomy", "home", "section"]
|
||||
-- content/mypage.md --
|
||||
---
|
||||
title: "No Inner!"
|
||||
---
|
||||
|
||||
{{< 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.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`))
|
||||
b, err := TestE(t, files)
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue