forked from mirror/gjson
Fix bounds out of range panic
This commit fixes an issues where gjson panics when the input json or path ends in incomplete quoted string. fixes #192
This commit is contained in:
parent
5100d6926a
commit
f0ee9ebde4
3
gjson.go
3
gjson.go
|
@ -498,6 +498,9 @@ func squash(json string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
|
if i >= len(json) {
|
||||||
|
return json
|
||||||
|
}
|
||||||
return json[:i+1]
|
return json[:i+1]
|
||||||
}
|
}
|
||||||
case '{', '[', '(':
|
case '{', '[', '(':
|
||||||
|
|
|
@ -2178,3 +2178,21 @@ func TestJoin152(t *testing.T) {
|
||||||
res := Get(json, "historical.summary.days.#.hours|@flatten|#.humidity.value")
|
res := Get(json, "historical.summary.days.#.hours|@flatten|#.humidity.value")
|
||||||
assert(t, res.Raw == `[92.0,92.0,91.0,91.0,67.0]`)
|
assert(t, res.Raw == `[92.0,92.0,91.0,91.0,67.0]`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue192(t *testing.T) {
|
||||||
|
|
||||||
|
assert(t, squash(`"000"hello`) == `"000"`)
|
||||||
|
assert(t, squash(`"000"`) == `"000"`)
|
||||||
|
assert(t, squash(`"000`) == `"000`)
|
||||||
|
assert(t, squash(`"`) == `"`)
|
||||||
|
|
||||||
|
assert(t, squash(`[000]hello`) == `[000]`)
|
||||||
|
assert(t, squash(`[000]`) == `[000]`)
|
||||||
|
assert(t, squash(`[000`) == `[000`)
|
||||||
|
assert(t, squash(`[`) == `[`)
|
||||||
|
assert(t, squash(`]`) == `]`)
|
||||||
|
|
||||||
|
testJSON := `0.#[[{}]].@valid:"000`
|
||||||
|
Get(testJSON, testJSON)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue