mirror of https://github.com/tidwall/gjson.git
Fix panic when key starts at-sign
This commit is contained in:
parent
dea71f728d
commit
c5e72cdf74
4
gjson.go
4
gjson.go
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue