diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b4a54740f..ad43d50643 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - [#3090](https://github.com/influxdb/influxdb/pull/3090): Remove database from TSDB index on DROP DATABASE. - [#2944](https://github.com/influxdb/influxdb/issues/2944): Don't require "WHERE time" when creating continuous queries. - [#3075](https://github.com/influxdb/influxdb/pull/3075): GROUP BY correctly when different tags have same value. +- [#3078](https://github.com/influxdb/influxdb/pull/3078): Fix CLI panic on malformed INSERT. ## v0.9.0 [2015-06-11] diff --git a/cmd/influx/main.go b/cmd/influx/main.go index 3882db39c3..aaec4fcfa3 100644 --- a/cmd/influx/main.go +++ b/cmd/influx/main.go @@ -425,16 +425,17 @@ func (c *CommandLine) parseInto(stmt string) string { } func (c *CommandLine) Insert(stmt string) error { - stmt = stmt[7:] - if strings.EqualFold(stmt[:4], "into") { - stmt = c.parseInto(stmt[5:]) + i, point := parseNextIdentifier(stmt) + if !strings.EqualFold(i, "insert") { + fmt.Printf("ERR: found %s, expected INSERT\n", i) + return nil } - if c.RetentionPolicy == "" { - c.RetentionPolicy = "default" + if i, r := parseNextIdentifier(point); strings.EqualFold(i, "into") { + point = c.parseInto(r) } _, err := c.Client.Write(client.BatchPoints{ Points: []client.Point{ - client.Point{Raw: stmt}, + client.Point{Raw: point}, }, Database: c.Database, RetentionPolicy: c.RetentionPolicy, diff --git a/cmd/influx/main_test.go b/cmd/influx/main_test.go index 01f299648a..3c42b3a5de 100644 --- a/cmd/influx/main_test.go +++ b/cmd/influx/main_test.go @@ -106,10 +106,13 @@ func TestParseCommand_Insert(t *testing.T) { cmd string }{ {cmd: "INSERT cpu,host=serverA,region=us-west value=1.0"}, - {cmd: " INSERT test.test cpu,host=serverA,region=us-west value=1.0"}, - {cmd: "INSERT test.test cpu,host=serverA,region=us-west value=1.0"}, - {cmd: "Insert test.test cpu,host=serverA,region=us-west value=1.0"}, - {cmd: "insert test.test cpu,host=serverA,region=us-west value=1.0"}, + {cmd: " INSERT cpu,host=serverA,region=us-west value=1.0"}, + {cmd: "INSERT cpu,host=serverA,region=us-west value=1.0"}, + {cmd: "insert cpu,host=serverA,region=us-west value=1.0 "}, + {cmd: "insert"}, + {cmd: "Insert "}, + {cmd: "insert c"}, + {cmd: "insert int"}, } for _, test := range tests {