From 676747adc5278400790b5bb0f198e52858c72b44 Mon Sep 17 00:00:00 2001 From: Andrew Stone Date: Tue, 31 May 2016 23:32:30 -0400 Subject: [PATCH] Fix 'index out of range' error --- param_test.go | 4 ++++ parse.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/param_test.go b/param_test.go index 48f5e42..7ee81d3 100644 --- a/param_test.go +++ b/param_test.go @@ -472,6 +472,10 @@ func TestStructErrors(t *testing.T) { t.Error("expected error parsing struct without key") } + if _, ok := err.(SyntaxError); !ok { + t.Error("expected SyntaxError parsing struct without key") + } + err = Parse(url.Values{"Struct[": {"llama"}}, &e) if err == nil { t.Error("expected error parsing malformed struct key") diff --git a/parse.go b/parse.go index b8c069d..6386da7 100644 --- a/parse.go +++ b/parse.go @@ -77,7 +77,7 @@ func primitive(key, keytail string, tipe reflect.Type, values []string) { } func keyed(tipe reflect.Type, key, keytail string) (string, string) { - if keytail[0] != '[' { + if keytail == "" || keytail[0] != '[' { panic(SyntaxError{ Key: kpath(key, keytail), Subtype: MissingOpeningBracket,