Fix infinite loop bug in lexer
This commit is contained in:
parent
74ea365c5a
commit
5edcf7b3a9
|
@ -398,7 +398,7 @@ func isSpace(r rune) bool {
|
|||
|
||||
// isEndOfLine reports whether r is an end-of-line character.
|
||||
func isEndOfLine(r rune) bool {
|
||||
return r == '\r' || r == '\n'
|
||||
return r == '\r' || r == '\n' || r == eof
|
||||
}
|
||||
|
||||
// isAlphaNumeric reports whether r is an alphabetic, digit, or underscore.
|
||||
|
|
|
@ -58,6 +58,14 @@ func TestCompile(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestInvalidCompile(t *testing.T) {
|
||||
qcompile, _ := NewCompiler(Config{})
|
||||
_, err := qcompile.CompileQuery(`#`)
|
||||
if err == nil {
|
||||
t.Fatal(errors.New("expecting an error"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyCompile(t *testing.T) {
|
||||
qcompile, _ := NewCompiler(Config{})
|
||||
_, err := qcompile.CompileQuery(``)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package qcode
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
|
@ -355,6 +356,10 @@ func (com *Compiler) compileQuery(op *Operation) (*Query, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if selRoot == nil {
|
||||
return nil, errors.New("invalid query")
|
||||
}
|
||||
|
||||
return &Query{selRoot}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue