From 27c108f47598c262a87a2cddc9a49bd0d7c7fadc Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Tue, 18 Oct 2016 17:13:15 -0700 Subject: [PATCH] fuzzing test on parse --- gjson.go | 28 +++++++++++++++++++++++++++- gjson_test.go | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gjson.go b/gjson.go index 0945497..01c15aa 100644 --- a/gjson.go +++ b/gjson.go @@ -27,6 +27,26 @@ const ( JSON ) +// String returns a string representation of the type. +func (t Type) String() string { + switch t { + default: + return "" + case Null: + return "Null" + case False: + return "False" + case Number: + return "Number" + case String: + return "String" + case True: + return "True" + case JSON: + return "JSON" + } +} + // Result represents a json value that is returned from Get(). type Result struct { // Type is the json type @@ -389,7 +409,13 @@ func tostr(json string) (raw string, str string) { break } } - return json[:i+1], unescape(json[1:i]) + var ret string + if i+1 < len(json) { + ret = json[:i+1] + } else { + ret = json[:i] + } + return ret, unescape(json[1:i]) } } return json, json[1:] diff --git a/gjson_test.go b/gjson_test.go index b92db2a..0740211 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -36,6 +36,7 @@ func TestRandomData(t *testing.T) { } lstr = string(b[:n]) GetBytes([]byte(lstr), "zzzz") + Parse(lstr) } }