From 83a17e8c2d3419feecd11019c425ca65344cbc45 Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Sat, 2 Apr 2016 18:33:25 -0500 Subject: [PATCH] Added early catching of invalid template values. Fixes #193 --- models/template.go | 38 +++++++++++++++++++++++++++++++++++++- static/js/app/templates.js | 3 +++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/models/template.go b/models/template.go index aa28867b..38527340 100644 --- a/models/template.go +++ b/models/template.go @@ -1,7 +1,9 @@ package models import ( + "bytes" "errors" + "html/template" "time" "github.com/jinzhu/gorm" @@ -33,7 +35,41 @@ func (t *Template) Validate() error { case t.Text == "" && t.HTML == "": return ErrTemplateMissingParameter } - return nil + var buff bytes.Buffer + // Test that the variables used in the template + // validate with no issues + td := struct { + Result + URL string + TrackingURL string + Tracker string + From string + }{ + Result{ + Email: "foo@bar.com", + FirstName: "Foo", + LastName: "Bar", + Position: "Test", + }, + "http://foo.bar", + "http://foo.bar/track", + "