Skip to content

Commit

Permalink
Fix shortcode error when closing without .Inner
Browse files Browse the repository at this point in the history
Fixes #10672
  • Loading branch information
bep committed Feb 23, 2023
1 parent 7d78a49 commit ae48507
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
10 changes: 1 addition & 9 deletions hugolib/shortcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,6 @@ func (s *shortcodeHandler) extractShortcode(ordinal, level int, source []byte, p
closed := false
const errorPrefix = "failed to extract shortcode"

fail := func(err error, i pageparser.Item) error {
return s.parseError(fmt.Errorf("%s: %w", errorPrefix, err), source, i.Pos())
}

Loop:
for {
currItem := pt.Next()
Expand Down Expand Up @@ -607,10 +603,6 @@ Loop:
// we trust the template on this:
// if there's no inner, we're done
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
}
Expand All @@ -625,7 +617,7 @@ Loop:
// return that error, more specific
continue
}
return sc, fail(fmt.Errorf("shortcode %q has no .Inner, yet a closing tag was provided", next.ValStr(source)), next)
return nil, fmt.Errorf("%s: shortcode %q does not evaluate .Inner or .InnerDeindent, yet a closing tag was provided", errorPrefix, next.ValStr(source))
}
}
if next.IsRightShortcodeDelim() {
Expand Down
2 changes: 1 addition & 1 deletion hugolib/shortcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ title: "No Inner!"
"layouts/shortcodes/noinner.html", `No inner here.`)

err := b.BuildE(BuildCfg{})
b.Assert(err.Error(), qt.Contains, filepath.FromSlash(`"content/mypage.md:4:21": failed to extract shortcode: shortcode "noinner" has no .Inner, yet a closing tag was provided`))
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`))
}

func TestShortcodeStableOutputFormatTemplates(t *testing.T) {
Expand Down

0 comments on commit ae48507

Please sign in to comment.