From 3fe1f20770fed00f96233783d1937ba692b5a816 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Fri, 19 May 2017 02:31:53 -0700 Subject: [PATCH] use json unmarshal instead of json decoder this should let us catch json syntax errors. --- template/parse.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/template/parse.go b/template/parse.go index 779886dfc..ad07729c8 100644 --- a/template/parse.go +++ b/template/parse.go @@ -264,13 +264,15 @@ func (r *rawTemplate) parsePostProcessor( func Parse(r io.Reader) (*Template, error) { // Create a buffer to copy what we read var buf bytes.Buffer - r = io.TeeReader(r, &buf) + if _, err := buf.ReadFrom(r); err != nil { + return nil, err + } // First, decode the object into an interface{}. We do this instead of // the rawTemplate directly because we'd rather use mapstructure to // decode since it has richer errors. var raw interface{} - if err := json.NewDecoder(r).Decode(&raw); err != nil { + if err := json.Unmarshal(buf.Bytes(), &raw); err != nil { return nil, err }