forked from mirror/gjson
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] == '@' {
|
if path[0] == '@' {
|
||||||
// possible modifier
|
// possible modifier
|
||||||
var ok bool
|
var ok bool
|
||||||
|
var npath string
|
||||||
var rjson string
|
var rjson string
|
||||||
path, rjson, ok = execModifier(json, path)
|
npath, rjson, ok = execModifier(json, path)
|
||||||
if ok {
|
if ok {
|
||||||
|
path = npath
|
||||||
if len(path) > 0 && (path[0] == '|' || path[0] == '.') {
|
if len(path) > 0 && (path[0] == '|' || path[0] == '.') {
|
||||||
res := Get(rjson, path[1:])
|
res := Get(rjson, path[1:])
|
||||||
res.Index = 0
|
res.Index = 0
|
||||||
|
|
|
@ -1984,3 +1984,9 @@ func TestParentSubQuery(t *testing.T) {
|
||||||
// should return two instances
|
// should return two instances
|
||||||
assert(t, res.String() == `["1.2.3","1.2.2"]`)
|
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