Skip to content

Commit

Permalink
Fix slice out of bounds panic
Browse files Browse the repository at this point in the history
fixes #196
  • Loading branch information
tidwall committed Dec 24, 2020
1 parent 9f58baa commit bf4efcb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions gjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit bf4efcb

Please sign in to comment.