use json unmarshal instead of json decoder

this should let us catch json syntax errors.
pull/4906/head
Matthew Hooker 9 years ago
parent e67d1fd676
commit 3fe1f20770
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1

@ -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
}

Loading…
Cancel
Save