fix: fromJSON should work with any JSON (#883)

* test: fromJSON should work with arrays

* fix: fromJSON should work with any JSON
This commit is contained in:
Mike Beaumont 2021-11-15 15:26:04 +01:00 committed by GitHub
parent 12fa4d703d
commit 09693ec5b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -327,8 +327,8 @@ func vmToJSON(vm *otto.Otto) {
} }
func vmFromJSON(vm *otto.Otto) { func vmFromJSON(vm *otto.Otto) {
fromJSON := func(str string) map[string]interface{} { fromJSON := func(str string) interface{} {
var dat map[string]interface{} var dat interface{}
err := json.Unmarshal([]byte(str), &dat) err := json.Unmarshal([]byte(str), &dat)
if err != nil { if err != nil {
log.Errorf("Unable to unmarshal: %v", err) log.Errorf("Unable to unmarshal: %v", err)

View file

@ -93,6 +93,7 @@ func TestEvaluate(t *testing.T) {
{"toJson({'foo':'bar'})", "{\n \"foo\": \"bar\"\n}", ""}, {"toJson({'foo':'bar'})", "{\n \"foo\": \"bar\"\n}", ""},
{"(fromJSON('{\"foo\":\"bar\"}')).foo", "bar", ""}, {"(fromJSON('{\"foo\":\"bar\"}')).foo", "bar", ""},
{"(fromJson('{\"foo\":\"bar\"}')).foo", "bar", ""}, {"(fromJson('{\"foo\":\"bar\"}')).foo", "bar", ""},
{"(fromJson('[\"foo\",\"bar\"]'))[1]", "bar", ""},
{"hashFiles('**/non-extant-files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""}, {"hashFiles('**/non-extant-files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
{"hashFiles('**/non-extant-files', '**/more-non-extant-files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""}, {"hashFiles('**/non-extant-files', '**/more-non-extant-files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
{"hashFiles('**/non.extant.files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""}, {"hashFiles('**/non.extant.files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},