Fix infinite loop bug in lexer

This commit is contained in:
Vikram Rangnekar 2019-04-20 19:42:08 -04:00
parent 74ea365c5a
commit 5edcf7b3a9
3 changed files with 14 additions and 1 deletions

View File

@ -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.

View File

@ -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(``)

View File

@ -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
}