Skip to content

Commit

Permalink
Fix panic when key starts at-sign
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Jul 15, 2019
1 parent dea71f7 commit c5e72cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -1841,9 +1841,11 @@ func Get(json, path string) Result {
if path[0] == '@' {
// possible modifier
var ok bool
var npath string
var rjson string
path, rjson, ok = execModifier(json, path)
npath, rjson, ok = execModifier(json, path)
if ok {
path = npath
if len(path) > 0 && (path[0] == '|' || path[0] == '.') {
res := Get(rjson, path[1:])
res.Index = 0
Expand Down
6 changes: 6 additions & 0 deletions gjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1984,3 +1984,9 @@ func TestParentSubQuery(t *testing.T) {
// should return two instances
assert(t, res.String() == `["1.2.3","1.2.2"]`)
}

func TestSingleModifier(t *testing.T) {
var data = `{"@key": "value"}`
assert(t, Get(data, "@key").String() == "value")
assert(t, Get(data, "\\@key").String() == "value")
}

0 comments on commit c5e72cd

Please sign in to comment.