3
0

Harden record value processing

This commit adds extra checks and for null/object/array types. NULL
values are gracefuly ignored whn found on root or under an attribute.
This commit is contained in:
Denis Arh
2022-11-13 12:05:17 +01:00
parent b469df74ac
commit 5187b63771
+19
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/cortezaproject/corteza-server/pkg/dal"
"github.com/cortezaproject/corteza-server/pkg/errors"
"github.com/spf13/cast"
"github.com/valyala/fastjson"
)
@@ -180,6 +181,15 @@ func (c *SimpleJsonDocColumn) Decode(raw any, r dal.ValueSetter) (err error) {
return
}
if root.Type() == fastjson.TypeNull {
// ignore NULL
return
}
if root.Type() != fastjson.TypeObject {
return errors.InvalidData("expecting valid JSON object for record-values")
}
if obj, err = root.Object(); err != nil {
return
}
@@ -191,6 +201,15 @@ func (c *SimpleJsonDocColumn) Decode(raw any, r dal.ValueSetter) (err error) {
continue
}
if auxvv.Type() == fastjson.TypeNull {
// ignore NULL
return
}
if auxvv.Type() != fastjson.TypeArray {
return errors.InvalidData("expecting valid JSON array for record-values at key %s, got %s", attr.Ident, root.Type())
}
if vv, err = auxvv.Array(); err != nil {
return
}