Skip to content

Commit

Permalink
[parser] digester: avoid infinite loop when an invalid token is seen (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm authored and jackysp committed May 5, 2019
1 parent bf3b1cf commit 671650d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions parser/digester.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func (d *sqlDigester) normalize(sql string) {
d.lexer.reset(sql)
for {
tok, pos, lit := d.lexer.scan()
if tok == invalid {
break
}
if tok == unicode.ReplacementChar && d.lexer.r.eof() {
break
}
Expand Down
1 change: 1 addition & 0 deletions parser/digester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *testSQLDigestSuite) TestNormalize(c *C) {
// test syntax error, it will be checked by parser, but it should not make normalize dead loop.
{"select * from t ignore index(", "select * from t ignore index"},
{"select /*+ ", "select "},
{"select * from 🥳", "select * from"},
}
for _, test := range tests {
actual := parser.Normalize(test.input)
Expand Down

0 comments on commit 671650d

Please sign in to comment.