"github.com/gohugoio/hugo/parser/pageparser"
"github.com/gohugoio/hugo/resources/page"
- _errors "github.com/pkg/errors"
-
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/common/text"
"github.com/gohugoio/hugo/common/urls"
var found bool
tmpl, found = s.TextTmpl().Lookup(templName)
if !found {
- return "", false, _errors.Errorf("no earlier definition of shortcode %q found", sc.name)
+ return "", false, errors.Errorf("no earlier definition of shortcode %q found", sc.name)
}
}
} else {
for _, v := range s.shortcodes {
s, more, err := renderShortcode(0, s.s, tplVariants, v, nil, p)
if err != nil {
- err = p.parseError(_errors.Wrapf(err, "failed to render shortcode %q", v.name), p.source.parsed.Input(), v.pos)
+ err = p.parseError(errors.Wrapf(err, "failed to render shortcode %q", v.name), p.source.parsed.Input(), v.pos)
return nil, false, err
}
hasVariants = hasVariants || more
switch {
case currItem.IsLeftShortcodeDelim():
next := pt.Peek()
+ if next.IsRightShortcodeDelim() {
+ // no name: {{< >}} or {{% %}}
+ return sc, errors.New("shortcode has no name")
+ }
if next.IsShortcodeClose() {
continue
}
// return that error, more specific
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() {
// Used to check if the template expects inner content.
templs := s.s.Tmpl().LookupVariants(sc.name)
if templs == nil {
- return nil, _errors.Errorf("template for shortcode %q not found", sc.name)
+ return nil, errors.Errorf("template for shortcode %q not found", sc.name)
}
sc.info = templs[0].(tpl.Info)
err := h.Execute(tmpl, buffer, data)
if err != nil {
- return "", _errors.Wrap(err, "failed to process shortcode")
+ return "", errors.Wrap(err, "failed to process shortcode")
}
return buffer.String(), nil
}
t.Fatalf("Shortcode rendered error %s.", err)
}
- if err == nil && expectError {
- t.Fatalf("No error from shortcode")
+ if expectError {
+ c.Assert(err, qt.ErrorMatches, expected)
+ return
}
h := b.H
`, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", wt)
}
+// #6866
+func TestShortcodeIncomplete(t *testing.T) {
+ t.Parallel()
+ CheckShortCodeMatchAndError(t, `{{< >}}`, ".*shortcode has no name.*", nil, true)
+}
+
func TestExtractShortcodes(t *testing.T) {
b := newTestSitesBuilder(t).WithSimpleConfigFile()