Fix slice out of bounds panic

fixes #196
This commit is contained in:
tidwall 2020-12-24 09:51:53 -07:00
parent 9f58baa7a6
commit bf4efcb3c1
2 changed files with 6 additions and 1 deletions

View File

@ -2592,7 +2592,7 @@ func execModifier(json, path string) (pathOut, res string, ok bool) {
// unwrap removes the '[]' or '{}' characters around json
func unwrap(json string) string {
json = trim(json)
if len(json) >= 2 && json[0] == '[' || json[0] == '{' {
if len(json) >= 2 && (json[0] == '[' || json[0] == '{') {
json = json[1 : len(json)-1]
}
return json

View File

@ -2200,3 +2200,8 @@ func TestIssue195(t *testing.T) {
`**********{**",**,,**,**,**,**,"",**,**,**,**,**,**,**,**,**,**]`
Get(testJSON, testJSON)
}
func TestIssue196(t *testing.T) {
testJSON := `[#.@pretty.@join:{""[]""preserve"3,"][{]]]`
Get(testJSON, testJSON)
}