filhodanuvem / gitql

💊 A git query language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Application panics on query with double quotes

filhodanuvem opened this issue · comments

This query works fine

gitql "select author, message, date from commits where author like 'Oliveira'"

This one, with a double quotes in the where clause raises an error

gitql "select author, message, date from commits where author like "Oliveira""
panic: interface conversion: parser.NodeExpr is *parser.NodeId, not *parser.NodeLiteral

goroutine 1 [running]:
github.com/cloudson/gitql/parser.gWC4(0xc000175b00, 0x167734b, 0x6, 0x169a8e8, 0x6)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/parser/parser.go:503 +0x6ce
github.com/cloudson/gitql/parser.gWC3(0x1b42700, 0x1, 0x1, 0xc0000ad29a, 0x6)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/parser/parser.go:429 +0x37
github.com/cloudson/gitql/parser.gWC2(0x1b42700, 0x1, 0x1b427c0, 0xc0000ad29a, 0x6)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/parser/parser.go:403 +0x37
github.com/cloudson/gitql/parser.gWhereConds(0x15, 0x0, 0x3, 0xc00013b520)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/parser/parser.go:386 +0x26
github.com/cloudson/gitql/parser.gWhere(0xc00013b520, 0x1, 0x1, 0x0)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/parser/parser.go:380 +0x6b
github.com/cloudson/gitql/parser.gSelect(0x1, 0x0, 0xc000175c98)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/parser/parser.go:119 +0x117
github.com/cloudson/gitql/parser.gProgram(0x7ffeefbffaa6, 0x44, 0xc0000bd348, 0xc000175d18)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/parser/parser.go:64 +0x1b4
github.com/cloudson/gitql/parser.AST(...)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/parser/parser.go:46
main.runQuery(0x7ffeefbffaa6, 0x44, 0x1674e2d, 0x1, 0x16764d2, 0x5, 0x1b76da0, 0xc000194200)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/main.go:158 +0x89
main.main.func2(0xc000192140, 0x7ffeefbffaa6, 0x44)
	/Users/runner/work/gitql/go/src/github.com/cloudson/gitql/main.go:101 +0x2a7
github.com/urfave/cli/v2.(*App).RunContext(0xc0000be300, 0x174a5e0, 0xc0000ac000, 0xc0000a8000, 0x2, 0x2, 0x0, 0x0)
	/Users/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.2.0/app.go:315 +0x6bf
github.com/urfave/cli/v2.(*App).Run(...)

I can take a look at this - is the expected behavior a syntax error for the query with two sets of double quotes, or should that be parse into a valid query ?

Nice @ginglis13 , to be honest, any of those would be a great contribution. A syntax error looks better for me.

Actually, this syntax

gitql "select author, message, date from commits where author like "Oliveira""

is equivalent to having no quotes at all

gitql "select author, message, date from commits where author like Oliveira"

So the question would be whether we should allow queries with no quotes.

Good catch @radiantly, in that case a syntax error is the only expected behavior.
I noticed that we have the same problem using the equal operator.

gitql "select author, message, date from commits where author = oliveira" 

I think you should escape the quotes?

gitql "select author, message, date from commits where author like \"Oliveira\""

Scaping the quotes working fine @llagerlof thanks for checking that.
Anyway, the application shouldn't panic in any case, so I've introduced an improvement to show a graceful parser error.