From bcad98c902f1f671dc1056d982421884fd5d4a60 Mon Sep 17 00:00:00 2001 From: Joseph Rothrock Date: Fri, 27 Feb 2015 13:33:36 -0800 Subject: [PATCH] malformed identifiers get through Issue: 1768 We weren't checking return codes from scanString. Added text descriptions for BADSTRING and BADESCAPE tokens. --- influxql/scanner.go | 2 +- influxql/scanner_test.go | 5 +++++ influxql/token.go | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/influxql/scanner.go b/influxql/scanner.go index 7a460d7e3af..ffcda356c14 100644 --- a/influxql/scanner.go +++ b/influxql/scanner.go @@ -137,7 +137,7 @@ func (s *Scanner) scanIdent() (tok Token, pos Pos, lit string) { } else if ch == '.' { buf.WriteRune(ch) } else if ch == '"' { - if tok0, pos0, lit0 := s.scanString(); tok == BADSTRING || tok == BADESCAPE { + if tok0, pos0, lit0 := s.scanString(); tok0 == BADSTRING || tok0 == BADESCAPE { return tok0, pos0, lit0 } else { _ = buf.WriteByte('"') diff --git a/influxql/scanner_test.go b/influxql/scanner_test.go index 0e43aea05e2..ba5d7e25fda 100644 --- a/influxql/scanner_test.go +++ b/influxql/scanner_test.go @@ -60,6 +60,11 @@ func TestScanner_Scan(t *testing.T) { {s: `foo`, tok: influxql.IDENT, lit: `foo`}, {s: `Zx12_3U_-`, tok: influxql.IDENT, lit: `Zx12_3U_`}, {s: `"foo".bar`, tok: influxql.IDENT, lit: `"foo".bar`}, + {s: `"foo\\bar"`, tok: influxql.IDENT, lit: `"foo\bar"`}, + {s: `"foo\bar"`, tok: influxql.BADESCAPE, lit: `\b`, pos: influxql.Pos{Line: 0, Char: 5}}, + {s: `"foo\"bar\""`, tok: influxql.IDENT, lit: `"foo"bar""`}, + {s: `test"`, tok: influxql.BADSTRING, lit: "", pos: influxql.Pos{Line: 0, Char: 3}}, + {s: `"test`, tok: influxql.BADSTRING, lit: `test`}, {s: `true`, tok: influxql.TRUE}, {s: `false`, tok: influxql.FALSE}, diff --git a/influxql/token.go b/influxql/token.go index 21298c7abf5..900cc741b9b 100644 --- a/influxql/token.go +++ b/influxql/token.go @@ -121,6 +121,8 @@ var tokens = [...]string{ NUMBER: "NUMBER", DURATION_VAL: "DURATION_VAL", STRING: "STRING", + BADSTRING: "BADSTRING", + BADESCAPE: "BADESCAPE", TRUE: "TRUE", FALSE: "FALSE",