Catch incomplete shortcode error

Currently, no name shortcodes (`{{< >}}`) enter unexpected branch and
throw `BUG: template info not set`. This patch checks if shortcode has
name or not earlier and throws specific error.

Closes #6866
This commit is contained in:
satotake 2021-05-24 21:59:02 +09:00 committed by GitHub
parent 10f60de89a
commit 845a7ba4fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View file

@ -65,8 +65,9 @@ title: "Title"
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
@ -341,6 +342,12 @@ func TestShortcodeWrappedInPIssue(t *testing.T) {
`, "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()