From bf4efcb3c18d1825b2988603dea5909140a5302b Mon Sep 17 00:00:00 2001 From: tidwall Date: Thu, 24 Dec 2020 09:51:53 -0700 Subject: [PATCH] Fix slice out of bounds panic fixes #196 --- gjson.go | 2 +- gjson_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gjson.go b/gjson.go index 852647c..360594d 100644 --- a/gjson.go +++ b/gjson.go @@ -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 diff --git a/gjson_test.go b/gjson_test.go index c7966a5..38e2db1 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -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) +}