Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DROP et al triggered an infinite loop. #15

Merged
merged 1 commit into from Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions parser.go
Expand Up @@ -159,8 +159,11 @@ LOOP:
// We don't do anything about these
S1:
for {
if p.eol(ctx) {
switch t := ctx.peek(); t.Type {
case EOF, SEMICOLON:
break S1
default:
ctx.advance()
}
}
case EOF:
Expand Down Expand Up @@ -1214,9 +1217,10 @@ func (p *Parser) parseIdents(ctx *parseCtx, idents ...TokenType) ([]string, erro
return strs, nil
}

// TODO: revisit what exactly this eol is meant to do
func (p *Parser) eol(ctx *parseCtx) bool {
ctx.skipWhiteSpaces()
switch t := ctx.peek(); t.Type {
switch t := ctx.next(); t.Type {
case EOF, SEMICOLON:
ctx.advance()
return true
Expand Down
4 changes: 4 additions & 0 deletions parser_test.go
Expand Up @@ -184,6 +184,10 @@ id bigint unsigned not null auto_increment
Input: "CREATE TABLE `fuga` ( `id` INTEGER NOT NULL AUTO_INCREMENT, CONSTRAINT `symbol` UNIQUE KEY `uniq_id` USING BTREE (`id`) )",
Expect: "CREATE TABLE `fuga` (\n`id` INTEGER NOT NULL AUTO_INCREMENT,\nCONSTRAINT `symbol` UNIQUE INDEX `uniq_id` USING BTREE (`id`)\n)",
},
{
Input: "DROP TABLE IF EXISTS `konboi_bug`",
Expect: "",
},
}

p := New()
Expand Down