Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Check if regexp matcher is nil. #607

Merged
merged 1 commit into from
Jan 29, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,18 @@ func TestStarPanic197(t *testing.T) {
require.Len(rows, 3)
}

func TestInvalidRegexp(t *testing.T) {
require := require.New(t)
e := newEngine(t)

ctx := newCtx()
_, iter, err := e.Query(ctx, `SELECT * FROM mytable WHERE s REGEXP("*main.go")`)
require.NoError(err)

_, err = sql.RowIterToRows(iter)
require.Error(err)
}

func TestIndexes(t *testing.T) {
e := newEngine(t)

Expand Down
4 changes: 3 additions & 1 deletion sql/expression/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ func (re *Regexp) compareRegexp(ctx *sql.Context, row sql.Row) (interface{}, err
},
}
}
matcher = re.pool.Get().(regex.Matcher)
if obj := re.pool.Get(); obj != nil {
matcher = obj.(regex.Matcher)
}
}
if matcher == nil {
return nil, err
Expand Down
13 changes: 13 additions & 0 deletions sql/expression/comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ func testRegexpCases(t *testing.T) {
}
}

func TestInvalidRegexp(t *testing.T) {
t.Helper()
require := require.New(t)

col1 := NewGetField(0, sql.Text, "col1", true)
invalid := NewLiteral("*col1", sql.Text)
r := NewRegexp(col1, invalid)
row := sql.NewRow("col1")

_, err := r.Eval(sql.NewEmptyContext(), row)
require.Error(err)
}

func TestIn(t *testing.T) {
testCases := []struct {
name string
Expand Down