Skip to content

Commit

Permalink
make regexp non-greedy
Browse files Browse the repository at this point in the history
  • Loading branch information
caibirdme committed Jul 5, 2019
1 parent 89d258d commit 2da2d5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ const (
paramPlaceHolder = "?"
)

var searchHandle = regexp.MustCompile(`{{\S+}}`)
var searchHandle = regexp.MustCompile(`{{\S+?}}`)

// NamedQuery is used for expressing complex query
func NamedQuery(sql string, data map[string]interface{}) (string, []interface{}, error) {
Expand Down
12 changes: 12 additions & 0 deletions builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,18 @@ func TestNamedQuery(t *testing.T) {
vals: []interface{}{1},
err: nil,
},
{
sql: `select {{foo}},{{bar}} from tb where age={{age}} and address in {{addr}}`,
data: map[string]interface{}{
"foo": "f1",
"bar": "f2",
"age": 10,
"addr": []string{"beijing", "shanghai", "chengdu"},
},
cond: `select ?,? from tb where age=? and address in (?,?,?)`,
vals: []interface{}{"f1", "f2", 10, "beijing", "shanghai", "chengdu"},
err: nil,
},
}
ass := assert.New(t)
for _, tc := range testData {
Expand Down

0 comments on commit 2da2d5a

Please sign in to comment.