]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix shortcode error when closing without .Inner
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 23 Feb 2023 07:38:51 +0000 (08:38 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 23 Feb 2023 08:36:14 +0000 (09:36 +0100)
Fixes #10672

hugolib/shortcode.go
hugolib/shortcode_test.go

index d3430cb8170334f8a17a438a1f5a59686c5469f4..13fe913a686066987c0d7bb412878f80365da800 100644 (file)
@@ -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()
@@ -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
                                }
@@ -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() {
index cd17e78749a6120049213b047edbeedc40d4a317..eac3de2ce2ce2a85e564ca1b077a95db6e3bf019 100644 (file)
@@ -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) {