From c38b1d47f978bc36858b51b8da9159173eff69ff Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 10 Jan 2020 19:34:59 +0100 Subject: Fix panic when injecting a template with nil data --- template.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/template.go b/template.go index c8c3d6a..dfb9a97 100644 --- a/template.go +++ b/template.go @@ -88,8 +88,19 @@ func (r *renderer) Render(w io.Writer, name string, data interface{}, ectx echo. // ectx is the raw *echo.context, not our own *Context ctx := ectx.Get("context").(*Context) + var renderData RenderData + if data == nil { + renderData = &struct { BaseRenderData }{ *NewBaseRenderData(ctx) } + } else { + var ok bool + renderData, ok = data.(RenderData) + if !ok { + return fmt.Errorf("data passed to template '%v' doesn't implement RenderData", name) + } + } + for _, plugin := range ctx.Server.plugins { - if err := plugin.Inject(ctx, name, data.(RenderData)); err != nil { + if err := plugin.Inject(ctx, name, renderData); err != nil { return fmt.Errorf("failed to run plugin '%v': %v", plugin.Name(), err) } } -- cgit v1.2.3