mirror of https://github.com/certusone/wasmd.git
Make IsJSONObjectWithTopLevelKey public
This commit is contained in:
parent
8fc4714a0b
commit
1e892acd36
|
@ -6,9 +6,9 @@ import (
|
|||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
// isJSONObjectWithTopLevelKey checks if the given bytes are a valid JSON object
|
||||
// IsJSONObjectWithTopLevelKey checks if the given bytes are a valid JSON object
|
||||
// with exactly one top-level key that is contained in the list of allowed keys.
|
||||
func isJSONObjectWithTopLevelKey(jsonBytes []byte, allowedKeys []string) error {
|
||||
func IsJSONObjectWithTopLevelKey(jsonBytes []byte, allowedKeys []string) error {
|
||||
document := map[string]interface{}{}
|
||||
if err := json.Unmarshal(jsonBytes, &document); err != nil {
|
||||
return sdkerrors.Wrap(ErrNotAJSONObject, "failed to unmarshal JSON to map")
|
||||
|
|
|
@ -103,7 +103,7 @@ func TestIsJSONObjectWithTopLevelKey(t *testing.T) {
|
|||
}
|
||||
for name, spec := range specs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
result := isJSONObjectWithTopLevelKey(spec.src, spec.allowedKeys)
|
||||
result := IsJSONObjectWithTopLevelKey(spec.src, spec.allowedKeys)
|
||||
if spec.exp == nil {
|
||||
require.NoError(t, result)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue