mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 14:40:43 +03:00
Fix crash for closing shortcode with no .Inner set
Fixes #6857 Closes #7330
This commit is contained in:
parent
145b3fcce3
commit
d6ed17c60f
2 changed files with 35 additions and 8 deletions
|
@ -496,20 +496,27 @@ Loop:
|
||||||
case currItem.IsRightShortcodeDelim():
|
case currItem.IsRightShortcodeDelim():
|
||||||
// we trust the template on this:
|
// we trust the template on this:
|
||||||
// if there's no inner, we're done
|
// if there's no inner, we're done
|
||||||
if !sc.isInline && !sc.info.ParseInfo().IsInner {
|
if !sc.isInline {
|
||||||
|
if sc.info == nil {
|
||||||
|
// This should not happen.
|
||||||
|
return sc, fail(errors.New("BUG: template info not set"), currItem)
|
||||||
|
}
|
||||||
|
if !sc.info.ParseInfo().IsInner {
|
||||||
return sc, nil
|
return sc, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case currItem.IsShortcodeClose():
|
case currItem.IsShortcodeClose():
|
||||||
next := pt.Peek()
|
next := pt.Peek()
|
||||||
if !sc.isInline && !sc.info.ParseInfo().IsInner {
|
if !sc.isInline {
|
||||||
|
if sc.info == nil || !sc.info.ParseInfo().IsInner {
|
||||||
if next.IsError() {
|
if next.IsError() {
|
||||||
// return that error, more specific
|
// return that error, more specific
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
return sc, fail(_errors.Errorf("shortcode %q has no .Inner, yet a closing tag was provided", next.Val), next)
|
return sc, fail(_errors.Errorf("shortcode %q has no .Inner, yet a closing tag was provided", next.Val), next)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if next.IsRightShortcodeDelim() {
|
if next.IsRightShortcodeDelim() {
|
||||||
// self-closing
|
// self-closing
|
||||||
pt.Consume(1)
|
pt.Consume(1)
|
||||||
|
|
|
@ -1316,3 +1316,23 @@ title: "Hugo Rocks!"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/gohugoio/hugo/issues/6857
|
||||||
|
func TestShortcodeNoInner(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
b := newTestSitesBuilder(t)
|
||||||
|
|
||||||
|
b.WithContent("page.md", `---
|
||||||
|
title: "No Inner!"
|
||||||
|
---
|
||||||
|
{{< noinner >}}{{< /noinner >}}
|
||||||
|
|
||||||
|
|
||||||
|
`).WithTemplatesAdded(
|
||||||
|
"layouts/shortcodes/noinner.html", `No inner here.`)
|
||||||
|
|
||||||
|
err := b.BuildE(BuildCfg{})
|
||||||
|
b.Assert(err.Error(), qt.Contains, `failed to extract shortcode: shortcode "noinner" has no .Inner, yet a closing tag was provided`)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue