From 42457f46dbc43046c2267c6da231c664b603235f Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 17 Nov 2016 13:13:43 +0800 Subject: [PATCH] fix index out of range bug. Signed-off-by: Bo-Yi Wu --- plugin.go | 2 +- plugin_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin.go b/plugin.go index 726292f..877631b 100644 --- a/plugin.go +++ b/plugin.go @@ -141,7 +141,7 @@ func parseTo(to []string, authorEmail string, matchEmail bool) []int64 { var ids []int64 attachEmail := true - for _, value := range to { + for _, value := range trimElement(to) { idArray := trimElement(strings.Split(value, ":")) // check id diff --git a/plugin_test.go b/plugin_test.go index ba541d3..e8212d2 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -146,6 +146,10 @@ func TestParseTo(t *testing.T) { ids = parseTo(input, "a@gmail.com", true) assert.Equal(t, []int64{0, 4, 5}, ids) + + // test empty ids + ids = parseTo([]string{"", " ", " "}, "a@gmail.com", true) + assert.Equal(t, 0, len(ids)) } func TestCheckFileExist(t *testing.T) {