From: Bjørn Erik Pedersen Date: Thu, 21 Jul 2016 15:18:55 +0000 (+0200) Subject: Check for nil Params in shortcode's Get X-Git-Tag: v0.17~225 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=593a546fc6b00d4a34eba3b3f5172fed2c100507;p=brevno-suite%2Fhugo Check for nil Params in shortcode's Get Fixes #2294 --- diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 8ea09fed..2de00fa9 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -66,6 +66,9 @@ func (scp *ShortcodeWithPage) Scratch() *Scratch { // Get is a convenience method to look up shortcode parameters by its key. func (scp *ShortcodeWithPage) Get(key interface{}) interface{} { + if scp.Params == nil { + return nil + } if reflect.ValueOf(scp.Params).Len() == 0 { return nil } diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index b30b5b51..cd2d9f7a 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -124,13 +124,6 @@ func TestPositionalParamIndexOutOfBounds(t *testing.T) { CheckShortCodeMatch(t, "{{< video 47238zzb >}}", "Playing Video error: index out of range for positional param at position 1", tem) } -// Issue #2294 -func TestPositionalParamNil(t *testing.T) { - tem := tpl.New() - tem.AddInternalShortcode("div.html", `
{{ .Inner }}
`) - CheckShortCodeMatch(t, "{{% div %}}**foo**{{% /div %}}", "
foo
", tem) -} - // some repro issues for panics in Go Fuzz testing func TestShortcodeGoFuzzRepros(t *testing.T) { tt := tpl.New() @@ -151,6 +144,16 @@ func TestNamedParamSC(t *testing.T) { CheckShortCodeMatch(t, `{{< img src = "one" class = "aspen grove" >}}`, ``, tem) } +// Issue #2294 +func TestNestedNamedMissingParam(t *testing.T) { + tem := tpl.New() + tem.AddInternalShortcode("acc.html", `
{{ .Inner }}
`) + tem.AddInternalShortcode("div.html", `
{{ .Inner }}
`) + CheckShortCodeMatch(t, + `{{% acc %}}{{% div %}}{{% /div %}}{{% /acc %}}`, + "
\n
", tem) +} + func TestIsNamedParamsSC(t *testing.T) { tem := tpl.New() tem.AddInternalShortcode("byposition.html", `
`)