Skip to content

Commit 5a72214

Browse files
authored
fix: Panic on invalid number as query (#260)
Co-authored-by: Kemal Hadimli <disq@users.noreply.github.com>
1 parent 3d0a969 commit 5a72214

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

parser/parser_table.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package parser
22

33
import (
4+
"errors"
45
"fmt"
56
)
67

@@ -1454,6 +1455,9 @@ func (p *Parser) parseStmt(pos Pos) (Expr, error) {
14541455
case p.matchKeyword(KeywordDesc), p.matchKeyword(KeywordDescribe):
14551456
expr, err = p.parseDescribeStmt(pos)
14561457
default:
1458+
if p.last() == nil {
1459+
return nil, errors.New("unexpected end of input")
1460+
}
14571461
return nil, fmt.Errorf("unexpected token: %q", p.last().String)
14581462
}
14591463
if err != nil {
@@ -1474,7 +1478,9 @@ func (p *Parser) parseStmt(pos Pos) (Expr, error) {
14741478
func (p *Parser) ParseStmts() ([]Expr, error) {
14751479
var stmts []Expr
14761480
for {
1477-
_ = p.lexer.consumeToken()
1481+
if err := p.lexer.consumeToken(); err != nil {
1482+
return nil, p.wrapError(err)
1483+
}
14781484
if p.lexer.isEOF() {
14791485
break
14801486
}

parser/parser_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func TestParser_InvalidSyntax(t *testing.T) {
186186
// Invalid ARRAY JOIN types (only ARRAY JOIN, LEFT ARRAY JOIN, and INNER ARRAY JOIN are valid)
187187
"SELECT * FROM t RIGHT ARRAY JOIN arr AS a", // RIGHT ARRAY JOIN not supported
188188
"SELECT * FROM t FULL ARRAY JOIN arr AS a", // FULL ARRAY JOIN not supported
189+
"00e1d", // invalid number that leaves lastToken nil
189190
}
190191
for _, sql := range invalidSQLs {
191192
parser := NewParser(sql)

0 commit comments

Comments
 (0)