Skip to content

Commit

Permalink
Fixing hash to JSON conversion
Browse files Browse the repository at this point in the history
`"` were not escaped, thus would lead
to invalid json (`{"x": "\"y"}` would become `{"x": ""y"}`)
  • Loading branch information
odino committed May 14, 2019
1 parent 047fa5b commit ca1bd63
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions evaluator/evaluator_test.go
Expand Up @@ -1546,7 +1546,7 @@ func TestHashFunctions(t *testing.T) {
expected string
}{
{`
h = {"a": 1, "b": 2, "c": {"x": 10, "y":20}}
h = {"a": 1, "b": 2, "c": {"x": 10, "y":20}, "e": "\"test"}
hk = h.keys()
hk = keys(h)
hv = h.values()
Expand All @@ -1557,7 +1557,7 @@ func TestHashFunctions(t *testing.T) {
hp = pop(h, "c")
hp = h.pop("d")
str(h)
`, `{"b": 2}`,
`, `{"b": 2, "e": "\"test"}`,
},
}

Expand Down
2 changes: 1 addition & 1 deletion object/object.go
Expand Up @@ -184,7 +184,7 @@ type String struct {

func (s *String) Type() ObjectType { return STRING_OBJ }
func (s *String) Inspect() string { return s.Value }
func (s *String) Json() string { return `"` + s.Inspect() + `"` }
func (s *String) Json() string { return `"` + strings.ReplaceAll(s.Inspect(), `"`, `\"`) + `"` }
func (s *String) ZeroValue() string { return "" }
func (s *String) HashKey() HashKey {
return HashKey{Type: s.Type(), Value: s.Value}
Expand Down

0 comments on commit ca1bd63

Please sign in to comment.