瀏覽代碼

Fix panic when injecting a template with nil data

master
Simon Ser 4 年之前
父節點
當前提交
c38b1d47f9
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: FDE7BE0E88F5E48
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. +12
    -1
      template.go

+ 12
- 1
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 // ectx is the raw *echo.context, not our own *Context
ctx := ectx.Get("context").(*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 { 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) return fmt.Errorf("failed to run plugin '%v': %v", plugin.Name(), err)
} }
} }


Loading…
取消
儲存